{"id":21443,"date":"2021-05-20T12:47:31","date_gmt":"2021-05-20T12:47:31","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=21443"},"modified":"2021-10-27T12:15:01","modified_gmt":"2021-10-27T12:15:01","slug":"complete-guide-and-tutorials-for-php-operators-with-example","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/complete-guide-and-tutorials-for-php-operators-with-example\/","title":{"rendered":"Complete Guide and Tutorials for PHP Operators with example"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What is Operators in PHP?<\/h2>\n\n\n\n<p>Operators are symbols which tell the PHP processor that certain actions are performed. The Add <code>(<strong><span class=\"has-inline-color has-vivid-red-color\">+<\/span><\/strong>)<\/code> symbol, for example, is an operator who tells PHP to add two variables or values, while the larger <code>(<strong><span class=\"has-inline-color has-vivid-red-color\">&gt;<\/span><\/strong>)<\/code> symbol is an operator who tells PHP to match two values. Do not presume that operators are functions alike. Such operators may be used instead of functioning (such as the PHP ternary).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"990\" height=\"430\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/PHP-operators-types.png\" alt=\"\" class=\"wp-image-21460\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/PHP-operators-types.png 990w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/PHP-operators-types-300x130.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/PHP-operators-types-768x334.png 768w\" sizes=\"auto, (max-width: 990px) 100vw, 990px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Arithmetic operators<\/li><li>Assignment operators<\/li><li>Comparison operators<\/li><li>Increment\/Decrement operators<\/li><li>Logical operators<\/li><li>String operators<\/li><li>Array operators<\/li><li>Spaceship operators<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Arithmetic operators:-<\/h3>\n\n\n\n<p>The arithmetic operator is used for basic arithmetical operations like adding, removing, multiplying, etc. These operators can be used to execute simple arithmetic behaviour of numerical values. The following table shows how the results are used and what results are obtained. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-14.png\" alt=\"\" class=\"wp-image-21444\" width=\"840\" height=\"358\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-14.png 848w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-14-300x128.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-14-768x328.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Example Result<\/li><li><code>+<\/code>&nbsp;Addition&nbsp;<code>$x + $y<\/code>&nbsp;Sum of&nbsp;<code>$x<\/code>&nbsp;and&nbsp;<code>$y<\/code><\/li><li><code>-&nbsp;<\/code>Subtraction&nbsp;<code>$x - $y<\/code>&nbsp;Difference of&nbsp;<code>$x<\/code>&nbsp;and<code>&nbsp;$y<\/code><\/li><li><code>*<\/code>&nbsp;Multiplication<code>&nbsp;$x * $y<\/code>&nbsp;Product of&nbsp;<code>$x&nbsp;<\/code>and&nbsp;<code>$y<\/code><\/li><li><code>\/&nbsp;<\/code>Division<code>&nbsp;$x \/ $y<\/code>&nbsp;Quotient of&nbsp;<code>$x<\/code>&nbsp;and&nbsp;<code>$y<\/code><\/li><li><code>%&nbsp;<\/code>Modulus&nbsp;<code>$x % $y<\/code>&nbsp;Remainder of&nbsp;<code>$x<\/code>&nbsp;divided by&nbsp;<code>$y<\/code><\/li><li><code>**&nbsp;<\/code>Exponentiation&nbsp;<code>$x ** $y<\/code>&nbsp;Result of raising $x to the&nbsp;<code>$y'th<\/code>&nbsp;power (Introduced in PHP 5.6)<\/li><\/ul>\n\n\n\n<p><strong>Example:<\/strong>&#8211; <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/9763d7e6c92bca5a56daedf2de09ddf3.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-15.png\" alt=\"\" class=\"wp-image-21445\" width=\"840\" height=\"246\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-15.png 714w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-15-300x87.png 300w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Assignment operators:-<\/h3>\n\n\n\n<p>To assign values to variables, PHP Assignment operators are used. The left side of the operand variable is replaced with the right side value. Variables are assigned by operators in this group. The most common assignment operator is =, which assigns the right side of the operand to the variable on the left. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"358\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-16.png\" alt=\"\" class=\"wp-image-21446\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-16.png 849w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-16-300x127.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-16-768x324.png 768w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Assignment Same as\u2026 Description<\/li><li><code>x = y x = y<\/code>&nbsp;The left operand gets set to the value of the expression on the right<\/li><li><code>x += y x = x + y<\/code>&nbsp;Addition<\/li><li><code>x -= y x = x - y<\/code>&nbsp;Subtraction<\/li><li><code>x *= y x = x * y&nbsp;<\/code>Multiplication<\/li><li><code>x \/= y x = x \/ y<\/code>&nbsp;Division<\/li><li><code>x %= y x = x % y<\/code>&nbsp;Modulus<\/li><\/ul>\n\n\n\n<p><strong>Example:-<\/strong> <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/d876c81963d89ca9366e1f214373f6ea.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-17.png\" alt=\"\" class=\"wp-image-21447\" width=\"834\" height=\"239\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-17.png 709w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-17-300x86.png 300w\" sizes=\"auto, (max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison operators:-<\/h3>\n\n\n\n<p>The operator for a comparison indicates the relationship shared by a number or a series, by two or more values. These php operators are simply used to compare the numbers or strings of the two values. Here we will instruct you how to use php operators to compare them. This type of PHP operator is essential to search for any inconsistencies or correlations between values and variables. It functions as booleans, returning the <code><strong><span class=\"has-inline-color has-vivid-red-color\">True<\/span><\/strong><\/code> or <code><strong><span class=\"has-inline-color has-vivid-red-color\">false<\/span><\/strong><\/code> value. For example, if the two variables you compares are not equal in value, using PHP not equal to the operator would show real. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"829\" height=\"503\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-18.png\" alt=\"\" class=\"wp-image-21448\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-18.png 829w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-300x182.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-768x466.png 768w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Example Result<\/li><li><code>==&nbsp;<\/code>Equal<code>&nbsp;$x == $y<\/code>&nbsp;Returns true if $x is equal to&nbsp;<code>$y<\/code><\/li><li><code>===&nbsp;<\/code>Identical&nbsp;<code>$x === $y<\/code>&nbsp;Returns true if $x is equal to $y, and they are of the same type<\/li><li><code>!=&nbsp;<\/code>Not equal&nbsp;<code>$x != $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is not equal to&nbsp;<code>$y<\/code><\/li><li><code>&lt;&gt;&nbsp;<\/code>Not equal&nbsp;<code>$x &lt;&gt; $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is not equal to&nbsp;<code>$y<\/code><\/li><li><code>!==&nbsp;<\/code>Not identical&nbsp;<code>$x !==<\/code>&nbsp;<code>$y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is not equal to&nbsp;<code>$y<\/code>, or they are not of the same type<\/li><li><code>&gt;<\/code>&nbsp;Greater than&nbsp;<code>$x &gt; $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is greater than&nbsp;<code>$y<\/code><\/li><li><code>&lt;<\/code>&nbsp;Less than $x&nbsp;<code>&lt; $y&nbsp;<\/code>Returns true if&nbsp;<code>$x<\/code>&nbsp;is less than&nbsp;<code>$y<\/code><\/li><li><code>&gt;=&nbsp;<\/code>Greater than or equal to&nbsp;<code>$x &gt;= $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is greater than or equal to&nbsp;<code>$y<\/code><\/li><li><code>&lt;=<\/code>&nbsp;Less than or equal to&nbsp;<code>$x &lt;= $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is less than or equal to&nbsp;<code>$y<\/code><\/li><\/ul>\n\n\n\n<p><strong>Example:- <\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/d24ea83b5cf98ff4814191440e7d19d3.js\"><\/script>\n\n\n\n<p><strong>Outputs:- <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-19.png\" alt=\"\" class=\"wp-image-21449\" width=\"138\" height=\"210\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Increment\/Decrement operators:-<\/h3>\n\n\n\n<p>These operators increase the value of a vector (increase) or decrease it (decrease). Often they are referred to as uniform operators since only one operator works. Operators for increasing and decreasing are employed to constantly increase or decrease a value by a factor of 1. Operator for pre-increment When added to the value, the new $x value is returned. For a clearer idea see the table below: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"828\" height=\"268\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-20.png\" alt=\"\" class=\"wp-image-21450\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-20.png 828w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-300x97.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-768x249.png 768w\" sizes=\"auto, (max-width: 828px) 100vw, 828px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Description<\/li><li><code>++$x<\/code>&nbsp;Pre-increment Increments&nbsp;<code>$x<\/code>&nbsp;by one, then returns&nbsp;<code>$x<\/code><\/li><li><code>$x++&nbsp;<\/code>Post-increment Returns&nbsp;<code>$x,<\/code>&nbsp;then increments&nbsp;<code>$x<\/code>&nbsp;by one<\/li><li><code>--$x&nbsp;<\/code>Pre-decrement Decrements&nbsp;<code>$x<\/code>&nbsp;by one, then returns&nbsp;<code>$x<\/code><\/li><li><code>$x--<\/code>&nbsp;Post-decrement Returns&nbsp;<code>$x<\/code>, then decrements&nbsp;<code>$x<\/code>&nbsp;by one<\/li><\/ul>\n\n\n\n<p><strong>Example:-<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/d9a3363c3b17c9b9cada53f07b80babc.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"226\" height=\"184\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-21.png\" alt=\"\" class=\"wp-image-21451\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Logical operators:-<\/h2>\n\n\n\n<p>They mix conditionals and are used mostly to track various conditions simultaneously. The PHP (or) operator, for example, tests that at least one in two is valid. You can use the PHP (and) operator if you want to verify if they are both valid. See the following table for clarifications: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"353\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-22.png\" alt=\"\" class=\"wp-image-21452\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-22.png 836w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-22-300x127.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-22-768x324.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Example Result<\/li><li>and And&nbsp;<code>$x<\/code>&nbsp;and&nbsp;<code>$y&nbsp;<\/code>True if both&nbsp;<code>$x<\/code>&nbsp;and&nbsp;<code>$y<\/code>&nbsp;are true<\/li><li><code>or Or $x<\/code>&nbsp;or&nbsp;<code>$y<\/code>&nbsp;True if either&nbsp;<code>$x<\/code>&nbsp;or&nbsp;<code>$y<\/code>&nbsp;is true<\/li><li><code>xor Xor<\/code>&nbsp;<code>$x xor $y&nbsp;<\/code>True if either&nbsp;<code>$x<\/code>&nbsp;or&nbsp;<code>$y&nbsp;<\/code>is true, but not both<\/li><li>&amp;&amp; And&nbsp;<code>$x &amp;&amp; $y<\/code>&nbsp;True if both&nbsp;<code>$x<\/code>&nbsp;and&nbsp;<code>$y<\/code>&nbsp;are true<\/li><li><code>|| Or<\/code>&nbsp;<code>$x || $y&nbsp;<\/code>True if either&nbsp;<code>$x<\/code>&nbsp;or&nbsp;<code>$y<\/code>&nbsp;is true<\/li><li>!<code>&nbsp;Not !$x&nbsp;<\/code>True if&nbsp;<code>$x&nbsp;<\/code>is not true<\/li><\/ul>\n\n\n\n<p><strong>Example:- <\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/fafb0ebe80b4ac3558bedba9f86efa21.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"128\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-23.png\" alt=\"\" class=\"wp-image-21453\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-23.png 611w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-23-300x63.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">String operators:-<\/h3>\n\n\n\n<p>Two string operators are available. The use of numerical values could produce unpredictable results:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The operator of PHP (.) is also known as the operator of concatenation. It connects individual strings.<\/li><li>The operator of PHP (.=) is known as the operator of the combined assignment. It attaches the argument to the one on the left on the right page.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"133\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-24.png\" alt=\"\" class=\"wp-image-21454\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-24.png 771w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-24-300x52.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-24-768x132.png 768w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Example Result<\/li><li><code>.&nbsp;<\/code>Concatenation&nbsp;<code>$txt1 . $txt2&nbsp;<\/code>Concatenation of&nbsp;<code>$txt1<\/code>&nbsp;and&nbsp;<code>$txt2<\/code><\/li><li><code>.=&nbsp;<\/code>Concatenation assignment&nbsp;<code>$txt1 .= $txt2<\/code>&nbsp;Appends&nbsp;<code>$txt2&nbsp;<\/code>to&nbsp;<code>$txt1<\/code><\/li><\/ul>\n\n\n\n<p><strong>Example:-<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/7f941df2c3ef213e49d7fadb0f1e860b.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"672\" height=\"64\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-25.png\" alt=\"\" class=\"wp-image-21455\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-25.png 672w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-25-300x29.png 300w\" sizes=\"auto, (max-width: 672px) 100vw, 672px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Array operators:- <\/h3>\n\n\n\n<p>For comparing arrays, the array operators are used. Use the operators mentioned below to compare different arrays. Be sure the right grammar is used. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"831\" height=\"393\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-26.png\" alt=\"\" class=\"wp-image-21456\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-26.png 831w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-26-300x142.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-26-768x363.png 768w\" sizes=\"auto, (max-width: 831px) 100vw, 831px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Operator Name Example Result<\/li><li><code>+<\/code>&nbsp;Union&nbsp;<code>$x + $y<\/code>&nbsp;Union of $x and $y<\/li><li><code>==<\/code>&nbsp;Equality&nbsp;<code>$x == $y&nbsp;<\/code>Returns true if&nbsp;<code>$x&nbsp;<\/code>and<code>&nbsp;$y&nbsp;<\/code>have the same key\/value pairs<\/li><li><code>===&nbsp;<\/code>Identity<code>&nbsp;$x === $y&nbsp;<\/code>Returns true if<code>&nbsp;$x<\/code>&nbsp;and&nbsp;<code>$y<\/code>&nbsp;have the same key\/value pairs in the same order and of the same types<\/li><li><code>!=&nbsp;<\/code>Inequality&nbsp;<code>$x != $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is not equal to&nbsp;<code>$y<\/code><\/li><li><code>&lt;&gt;&nbsp;<\/code>Inequality&nbsp;<code>$x &lt;&gt; $y&nbsp;<\/code>Returns true if&nbsp;<code>$x<\/code>&nbsp;is not equal to<code>&nbsp;$y<\/code><\/li><li><code>!==&nbsp;<\/code>Non-identity&nbsp;<code>$x !== $y<\/code>&nbsp;Returns true if&nbsp;<code>$x<\/code>&nbsp;is not identical to&nbsp;<code>$y<\/code><\/li><\/ul>\n\n\n\n<p><strong>Example:-<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/c03c469c56b222e74c8de5c3a98fafb3.js\"><\/script>\n\n\n\n<p><strong>Output:- <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"681\" height=\"128\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-27.png\" alt=\"\" class=\"wp-image-21457\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-27.png 681w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-27-300x56.png 300w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Spaceship operators:-<\/h2>\n\n\n\n<p>PHP 7 adds a new spacecraft operator <code><span class=\"has-inline-color has-black-color\">(<\/span><span class=\"has-inline-color has-vivid-red-color\"><strong>&lt;=&gt;<\/strong><\/span><span class=\"has-inline-color has-black-color\">)<\/span><\/code> that can be used to compare two terms. The combined contrast operator is also known.<\/p>\n\n\n\n<p>If the two operands are identical, the spacecraft operator returns<code><strong><span class=\"has-inline-color has-vivid-red-color\"> 0<\/span><\/strong><\/code>, <code><strong><span class=\"has-inline-color has-vivid-red-color\">1<\/span><\/strong><\/code> if the left is larger, and <strong><code><span class=\"has-inline-color has-vivid-red-color\">-1<\/span><\/code><\/strong> if the right is larger. The three-way comparison is essentially shown as seen in the next table: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-28.png\" alt=\"\" class=\"wp-image-21458\" width=\"774\" height=\"285\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-28.png 774w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-28-300x110.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-28-768x283.png 768w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<p><strong>Example:- <\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/AdarshAshwani\/8afc870dac84c4cf782f334f77afb41d.js\"><\/script>\n\n\n\n<p><strong>Output:-<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"228\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-29.png\" alt=\"\" class=\"wp-image-21459\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-29.png 682w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2021\/05\/image-29-300x100.png 300w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_40107\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_22108\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_40107\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>What is Operators in PHP? Operators are symbols which tell the PHP processor that certain actions are performed. The Add (+) symbol, for example, is an operator who tells PHP to add two variables or values, while the larger (&gt;) symbol is an operator who tells PHP to match two values. Do not presume that&#8230;<\/p>\n","protected":false},"author":25,"featured_media":21461,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5150],"tags":[6637,6189,6184,6185,6632,6638,6187,6636,6639,6188,6633,6634,6635],"class_list":["post-21443","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-arithmetic-operators-3","tag-array-operators","tag-assignment-operators","tag-comparison-operators","tag-complete-guide-and-tutorials-for-php-operators-with-example","tag-increment-decrement-operators","tag-logical-operators","tag-operators-in-php","tag-spaceship-operators","tag-string-operators","tag-tutorials-for-php-operators","tag-tutorials-for-php-operators-with-example","tag-what-is-operators-in-php"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/21443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=21443"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/21443\/revisions"}],"predecessor-version":[{"id":24381,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/21443\/revisions\/24381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/21461"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=21443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=21443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=21443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}