{"id":152,"date":"2016-07-20T08:15:06","date_gmt":"2016-07-20T08:15:06","guid":{"rendered":"https:\/\/barkhane.com\/php\/2016\/07\/20\/operator-in-php\/"},"modified":"2024-03-03T15:04:58","modified_gmt":"2024-03-03T15:04:58","slug":"operator-in-php","status":"publish","type":"post","link":"https:\/\/barkhane.com\/php\/operator-in-php\/","title":{"rendered":"Operator PHP"},"content":{"rendered":"<h2>What is Operator in PHP ?<\/h2>\n<blockquote><p>Operator in PHP : An <b>operator<\/b> is a symbol that tells \u00a0to perform specific mathematical or logical functions. In PHP\u00a0there \u00a0are following\u00a0types of <b>operators<\/b><\/p>\n<ol class=\"list\">\n<li>Arithmetic Operators<\/li>\n<li>Comparison Operators<\/li>\n<li>Logical (or Relational) Operators<\/li>\n<li>Assignment Operators<\/li>\n<li>Conditional (or ternary) Operators<\/li>\n<\/ol>\n<\/blockquote>\n<h2>Arithmetic Operators in PHP:<\/h2>\n<p>Arithmetic Operators are those operators which perform Calculation .If we want to perform Mathematical operation then \u00a0Arithmetic Operators are use \u00a0like +,-,*,\/,%,++,&#8211;. Generally it is used for calculation between variables.<\/p>\n<p>Assume $x and $y \u00a0are two <a href=\"https:\/\/barkhane.com\/php\/php-variable-deceleration\/\" target=\"_blank\" rel=\"noopener\">variables <\/a>having value $x=10 ,$y=5, Then the Result will be give by Operators are<\/p>\n<table class=\" aligncenter\" width=\"604\">\n<tbody>\n<tr>\n<td width=\"14%\"><strong>Operator<\/strong><\/td>\n<td><strong>Example<\/strong><\/td>\n<td><strong>Result<\/strong><\/td>\n<td><strong>Operation Performed<\/strong><\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>$x + $y<\/td>\n<td>30<\/td>\n<td>Adds two operands<\/td>\n<\/tr>\n<tr>\n<td>&#8211;<\/td>\n<td>$x- $y<\/td>\n<td>5<\/td>\n<td>Subtracts second operand from the first<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>$x* $y<\/td>\n<td>50<\/td>\n<td>Multiply both operands<\/td>\n<\/tr>\n<tr>\n<td>\/<\/td>\n<td>$x \/ $y<\/td>\n<td>2<\/td>\n<td>Divide numerator by de-numerator<\/td>\n<\/tr>\n<tr>\n<td>%<\/td>\n<td>$x % $y<\/td>\n<td>0<\/td>\n<td>Modulus Operator and remainder of after an integer division<\/td>\n<\/tr>\n<tr>\n<td>++<\/td>\n<td>$x++<\/td>\n<td>11<\/td>\n<td>Increment operator, increases integer value by one<\/td>\n<\/tr>\n<tr>\n<td>&#8212;<\/td>\n<td>$x&#8211;<\/td>\n<td>9<\/td>\n<td>Decrement operator, decreases integer value by ones<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Comparison Operators\u00a0in PHP:<\/h2>\n<p>Comparison Operators are those operators which perform Comparison .If we want to perform any\u00a0Comparison operation then Comparison Operators are use \u00a0like ==,!=,&lt;,&gt;,&gt;=,&lt;=. Generally it is used for Comparison between variables or for to check whether the desired value is available or not.<\/p>\n<p>Assume $x and $y \u00a0are two <a href=\"https:\/\/barkhane.com\/php\/php-variable-deceleration\/\" target=\"_blank\" rel=\"noopener\">variables <\/a>having value $x=10 ,$y=5, Then the Result will be give by Operators are<\/p>\n<table class=\" aligncenter\" width=\"633\">\n<tbody>\n<tr>\n<td width=\"13%\"><strong>Operator<\/strong><\/td>\n<td width=\"18%\"><strong>Example<\/strong><\/td>\n<td width=\"11%\"><strong>Result <\/strong><\/td>\n<td width=\"56%\"><strong>Operation Performed\u00a0<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">==<\/td>\n<td width=\"18%\">($x == $y)<\/td>\n<td width=\"11%\">False<\/td>\n<td width=\"56%\">If value of two operands are equal or not, if yes then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">!=<\/td>\n<td width=\"18%\">($x != $y)<\/td>\n<td width=\"11%\">True<\/td>\n<td width=\"56%\">If value of two operands are equal or not, if values are not equal then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">&gt;<\/td>\n<td width=\"18%\">($x \u00a0&gt; $y)<\/td>\n<td width=\"11%\">True<\/td>\n<td width=\"56%\">If value of left operand is greater than value of right operand, if yes then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">&lt;<\/td>\n<td width=\"18%\">($x \u00a0&lt; $y)<\/td>\n<td width=\"11%\">False<\/td>\n<td width=\"56%\">If value of left operand is less than value of right operand, if yes then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">&gt;=<\/td>\n<td width=\"18%\">($x \u00a0&gt;= $y)<\/td>\n<td width=\"11%\">True<\/td>\n<td width=\"56%\">If value of left operand is greater than or equal to value of right operand, if yes then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">&lt;=<\/td>\n<td width=\"18%\">($x \u00a0&lt;= $y)<\/td>\n<td width=\"11%\">False<\/td>\n<td width=\"56%\">If value of left operand is less than or equal to value of right operand, if yes then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0===<\/td>\n<td>\u00a0($x===$y)<\/td>\n<td>\u00a0False<\/td>\n<td>\u00a0If value of two operands are equal and the <a href=\"https:\/\/barkhane.com\/php\/understanding-php-data-type\/\" target=\"_blank\" rel=\"noopener\">data types <\/a>are same\u00a0, if yes then condition becomes true.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Logical \u00a0Operators\u00a0in PHP:<\/h2>\n<p>Logical \u00a0Operators is also called\u00a0Relational Operators. These operator Checks the logic of the condition where the condition goes right or wrong.For example we want to check that give value is according to us then perform first Condition if not then Second condition<br \/>\nAssume $x and $y \u00a0are two\u00a0 <a href=\"https:\/\/barkhane.com\/php\/php-variable-deceleration\/\" target=\"_blank\" rel=\"noopener\">variables <\/a> having value $x=10 ,$y=5, Then the Result will be give by Operators are<\/p>\n<table class=\" aligncenter\" style=\"height: 346px\" width=\"794\">\n<tbody>\n<tr>\n<td width=\"13%\"><strong>Operator<\/strong><\/td>\n<td><strong>Example<\/strong><\/td>\n<td><strong>Name of Logical Operator<\/strong><\/td>\n<td><strong>Operation Performed\u00a0<\/strong><\/td>\n<\/tr>\n<tr>\n<td>and<\/td>\n<td>($x and $y) is true.<\/td>\n<td>AND operator.<\/td>\n<td>If both the operands are true then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td>or<\/td>\n<td>($x or $y) is true.<\/td>\n<td>OR Operator.<\/td>\n<td>If any of the two operands are non zero then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td>!<\/td>\n<td>!($x &amp;&amp; $y) is false.<\/td>\n<td>NOT Operator.<\/td>\n<td>Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.<\/td>\n<\/tr>\n<tr>\n<td>&amp;&amp;<\/td>\n<td>($x &amp;&amp; $y) is true.<\/td>\n<td>AND operator.<\/td>\n<td>If both the operands are non zero then condition becomes true.<\/td>\n<\/tr>\n<tr>\n<td>||<\/td>\n<td>($x || $y) is true.<\/td>\n<td>OR Operator.<\/td>\n<td>If any of the two operands are non zero then condition becomes true.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Assignment Operators\u00a0in PHP:<\/h2>\n<p>Assignment Operators are those operator which perform assignment of value in variable according to operator.In \u00a0php there are many\u00a0Assignment Operators .Don\\&#8217;t get Confuse between <strong>\\&#8221;=\\&#8221;<\/strong> and <strong>\\&#8221;==\\&#8221;<\/strong>.in PHP\u00a0<strong>\\&#8221;=\\&#8221;<\/strong> is <strong>assignment operator<\/strong> where as\u00a0<strong>\\&#8221;==\\&#8221;<\/strong> is <strong>Comparison operator\u00a0<\/strong><\/p>\n<table width=\"750\">\n<tbody>\n<tr>\n<td width=\"8%\"><strong>Operator<\/strong><\/td>\n<td width=\"13%\"><strong>Example<\/strong><\/td>\n<td width=\"16%\"><strong>Working As<\/strong><\/td>\n<td width=\"60%\"><strong>Operation Performed<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">=<\/td>\n<td width=\"13%\">$z = $x + $y<\/td>\n<td width=\"16%\">assign value of $x + $y into $z<\/td>\n<td width=\"60%\">Simple assignment operator, Assigns values from right side operands to left side operand<\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">+=<\/td>\n<td width=\"13%\">$z += $x<\/td>\n<td width=\"16%\">$z = $z + $x<\/td>\n<td width=\"60%\">Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand<\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">-=<\/td>\n<td width=\"13%\">$z -= $x<\/td>\n<td width=\"16%\">$z = $z -$x<\/td>\n<td width=\"60%\">Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand<\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">*=<\/td>\n<td width=\"13%\">$z *= $x<\/td>\n<td width=\"16%\">$z = $z * $x<\/td>\n<td width=\"60%\">Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand<\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">\/=<\/td>\n<td width=\"13%\">$z \/= $x<\/td>\n<td width=\"16%\">$z = $z \/ $x<\/td>\n<td width=\"60%\">Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand<\/td>\n<\/tr>\n<tr>\n<td width=\"8%\">%=<\/td>\n<td width=\"13%\">$z %= $x<\/td>\n<td width=\"16%\">$z = $z % $x<\/td>\n<td width=\"60%\">Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Conditional Operator\u00a0in PHP:<\/h2>\n<p>Conditional Operator is sometimes also called\u00a0ternary operator.In ternary Operator \u00a0first Checks an expression for a true or false value and then perform given statements depending upon the result of the evaluation.<\/p>\n<p>Assume $x and $y \u00a0are two\u00a0 <a href=\"https:\/\/barkhane.com\/php\/php-variable-deceleration\/\" target=\"_blank\" rel=\"noopener\">variables <\/a> having value $x=10 ,$y=5, Then the Result will be give by Operators are<\/p>\n<p>&nbsp;<\/p>\n<table class=\" aligncenter\" width=\"638\">\n<tbody>\n<tr>\n<td width=\"13%\"><strong>Operator<\/strong><\/td>\n<td width=\"35%\"><strong>Example<\/strong><\/td>\n<td width=\"11%\"><strong>Result<\/strong><\/td>\n<td width=\"39%\"><strong>Operration Performed<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"13%\">? :<\/td>\n<td width=\"35%\">\u00a0(($x &lt; $y ) ? $z=$x :$z=$y);<\/td>\n<td width=\"11%\">$z=5<\/td>\n<td width=\"39%\">If Condition is true ? Then value $x : Otherwise value $y<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>What is Operator in PHP ? Operator in PHP : An operator is a symbol that tells \u00a0to perform specific [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}