{"id":45,"date":"2023-05-06T02:50:52","date_gmt":"2023-05-06T02:50:52","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=45"},"modified":"2023-05-06T02:50:52","modified_gmt":"2023-05-06T02:50:52","slug":"what-are-the-different-types-of-operators-in-php","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/06\/what-are-the-different-types-of-operators-in-php\/","title":{"rendered":"What are the different types of operators in PHP?"},"content":{"rendered":"\n<p>PHP Operator is a symbol used to perform operations on operands. In simple words, operators are used to perform operations on variables or values.<\/p>\n\n\n\n<p><strong>Arithmetic Operators<\/strong><\/p>\n\n\n\n<p>The PHP arithmetic operators are used to perform common arithmetic operations such as addition, subtraction, etc. with numeric values.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Operator<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Example<\/strong><\/td><td><strong>Explanation<\/strong><\/td><\/tr><tr><td>+<\/td><td>Addition<\/td><td>$a + $b<\/td><td>Sum of operands<\/td><\/tr><tr><td>&#8211;<\/td><td>Subtraction<\/td><td>$a &#8211; $b<\/td><td>Difference of operands<\/td><\/tr><tr><td>*<\/td><td>Multiplication<\/td><td>$a * $b<\/td><td>Product of operands<\/td><\/tr><tr><td>\/<\/td><td>Division<\/td><td>$a \/ $b<\/td><td>Quotient of operands<\/td><\/tr><tr><td>%<\/td><td>Modulus<\/td><td>$a % $b<\/td><td>Remainder of operands<\/td><\/tr><tr><td>**<\/td><td>Exponentiation<\/td><td>$a ** $b<\/td><td>$a raised to the power $b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Assignment Operators<\/strong><\/p>\n\n\n\n<p>The assignment operators are used to assign value to different variables. The basic assignment operator is &#8220;=&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>=<\/td><td>Assign<\/td><td>$a = $b<\/td><td>The value of the right operand is assigned to the left operand.<\/td><\/tr><tr><td>+=<\/td><td>Add then Assign<\/td><td>$a += $b<\/td><td>Addition same as $a = $a + $b<\/td><\/tr><tr><td>-=<\/td><td>Subtract then Assign<\/td><td>$a -= $b<\/td><td>Subtraction same as $a = $a &#8211; $b<\/td><\/tr><tr><td>*=<\/td><td>Multiply then Assign<\/td><td>$a *= $b<\/td><td>Multiplication same as $a = $a * $b<\/td><\/tr><tr><td>\/=<\/td><td>Divide then Assign(quotient)<\/td><td>$a \/= $b<\/td><td>Find quotient same as $a = $a \/ $b<\/td><\/tr><tr><td>%=<\/td><td>Divide then Assign(remainder)<\/td><td>$a %= $b<\/td><td>Find remainder same as $a = $a % $b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Bitwise Operators<\/strong><\/p>\n\n\n\n<p>The bitwise operators are used to perform bit-level operations on operands. These operators allow the evaluation and manipulation of specific bits within the integer.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>&amp;<\/td><td>And<\/td><td>$a &amp; $b<\/td><td>Bits that are 1 in both $a and $b are set to 1, otherwise 0.<\/td><\/tr><tr><td>|<\/td><td>Or (Inclusive or)<\/td><td>$a | $b<\/td><td>Bits that are 1 in either $a or $b are set to 1<\/td><\/tr><tr><td>^<\/td><td>Xor (Exclusive or)<\/td><td>$a ^ $b<\/td><td>Bits that are 1 in either $a or $b are set to 0.<\/td><\/tr><tr><td>~<\/td><td>Not<\/td><td>~$a<\/td><td>Bits that are 1 set to 0 and bits that are 0 are set to 1<\/td><\/tr><tr><td>&lt;&lt;<\/td><td>Shift left<\/td><td>$a &lt;&lt; $b<\/td><td>Left shift the bits of operand $a $b steps<\/td><\/tr><tr><td>&gt;&gt;<\/td><td>Shift right<\/td><td>$a &gt;&gt; $b<\/td><td>Right shift the bits of $a operand by $b number of places<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Comparison Operators<\/strong><\/p>\n\n\n\n<p>Comparison operators allow comparing two values, such as number or string. Below the list of comparison operators are given:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>==<\/td><td>Equal<\/td><td>$a == $b<\/td><td>Return TRUE if $a is equal to $b<\/td><\/tr><tr><td>===<\/td><td>Identical<\/td><td>$a === $b<\/td><td>Return TRUE if $a is equal to $b, and they are of same data type<\/td><\/tr><tr><td>!==<\/td><td>Not identical<\/td><td>$a !== $b<\/td><td>Return TRUE if $a is not equal to $b, and they are not of same data type<\/td><\/tr><tr><td>!=<\/td><td>Not equal<\/td><td>$a != $b<\/td><td>Return TRUE if $a is not equal to $b<\/td><\/tr><tr><td>&lt;&gt;<\/td><td>Not equal<\/td><td>$a &lt;&gt; $b<\/td><td>Return TRUE if $a is not equal to $b<\/td><\/tr><tr><td>&lt;<\/td><td>Less than<\/td><td>$a &lt; $b<\/td><td>Return TRUE if $a is less than $b<\/td><\/tr><tr><td>&gt;<\/td><td>Greater than<\/td><td>$a &gt; $b<\/td><td>Return TRUE if $a is greater than $b<\/td><\/tr><tr><td>&lt;=<\/td><td>Less than or equal to<\/td><td>$a &lt;= $b<\/td><td>Return TRUE if $a is less than or equal $b<\/td><\/tr><tr><td>&gt;=<\/td><td>Greater than or equal to<\/td><td>$a &gt;= $b<\/td><td>Return TRUE if $a is greater than or equal $b<\/td><\/tr><tr><td>&lt;=&gt;<\/td><td>Spaceship<\/td><td>$a &lt;=&gt;$b<\/td><td>Return -1 if $a is less than $bReturn 0 if $a is equal $bReturn 1 if $a is greater than $b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Incrementing\/Decrementing Operators<\/strong><\/p>\n\n\n\n<p>The increment and decrement operators are used to increase and decrease the value of a variable.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td rowspan=\"2\">++<\/td><td rowspan=\"2\">Increment<\/td><td>++$a<\/td><td>Increment the value of $a by one, then return $a<\/td><\/tr><tr><td>$a++<\/td><td>Return $a, then increment the value of $a by one<\/td><\/tr><tr><td rowspan=\"2\">&#8212;<\/td><td rowspan=\"2\">decrement<\/td><td>&#8211;$a<\/td><td>Decrement the value of $a by one, then return $a<\/td><\/tr><tr><td>$a&#8211;<\/td><td>Return $a, then decrement the value of $a by one<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Logical Operators<\/strong><\/p>\n\n\n\n<p>The logical operators are used to perform bit-level operations on operands. These operators allow the evaluation and manipulation of specific bits within the integer.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>and<\/td><td>And<\/td><td>$a and $b<\/td><td>Return TRUE if both $a and $b are true<\/td><\/tr><tr><td>Or<\/td><td>Or<\/td><td>$a or $b<\/td><td>Return TRUE if either $a or $b is true<\/td><\/tr><tr><td>xor<\/td><td>Xor<\/td><td>$a xor $b<\/td><td>Return TRUE if either $ or $b is true but not both<\/td><\/tr><tr><td>!<\/td><td>Not<\/td><td>! $a<\/td><td>Return TRUE if $a is not true<\/td><\/tr><tr><td>&amp;&amp;<\/td><td>And<\/td><td>$a &amp;&amp; $b<\/td><td>Return TRUE if either $a and $b are true<\/td><\/tr><tr><td>||<\/td><td>Or<\/td><td>$a || $b<\/td><td>Return TRUE if either $a or $b is true<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>String Operators<\/strong><\/p>\n\n\n\n<p>The string operators are used to perform the operation on strings. There are two string operators in PHP, which are given below:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>.<\/td><td>Concatenation<\/td><td>$a . $b<\/td><td>Concatenate both $a and $b<\/td><\/tr><tr><td>.=<\/td><td>Concatenation and Assignment<\/td><td>$a .= $b<\/td><td>First concatenate $a and $b, then assign the concatenated string to $a, e.g. $a = $a . $b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Array Operators<\/strong><\/p>\n\n\n\n<p>The array operators are used in case of array. Basically, these operators are used to compare the values of arrays.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Operator<\/td><td>Name<\/td><td>Example<\/td><td>Explanation<\/td><\/tr><tr><td>+<\/td><td>Union<\/td><td>$a + $y<\/td><td>Union of $a and $b<\/td><\/tr><tr><td>==<\/td><td>Equality<\/td><td>$a == $b<\/td><td>Return TRUE if $a and $b have same key\/value pair<\/td><\/tr><tr><td>!=<\/td><td>Inequality<\/td><td>$a != $b<\/td><td>Return TRUE if $a is not equal to $b<\/td><\/tr><tr><td>===<\/td><td>Identity<\/td><td>$a === $b<\/td><td>Return TRUE if $a and $b have same key\/value pair of same type in same order<\/td><\/tr><tr><td>!==<\/td><td>Non-Identity<\/td><td>$a !== $b<\/td><td>Return TRUE if $a is not identical to $b<\/td><\/tr><tr><td>&lt;&gt;<\/td><td>Inequality<\/td><td>$a &lt;&gt; $b<\/td><td>Return TRUE if $a is not equal to $b<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>PHP Operator is a symbol used to perform operations on operands. In simple words, operators&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/45"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions\/46"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}