Added Comparison Operators (#32078)

Also removed HTML tags and wrote everything in markdown syntax
This commit is contained in:
Berat Aşıcı
2019-03-29 02:27:09 +03:00
committed by Randell Dawson
parent d7736fb8be
commit ea700759fe

View File

@ -1,84 +1,56 @@
--- ---
title: PHP Operators title: PHP Operators
--- ---
## PHP Operators ## PHP Operators
<p>Operators are used to perform operations on variables and values.</p> Operators are used to perform operations on variables and values.
<p>PHP divides the operators in the following groups:</p>
<ul> PHP divides the operators in the following groups:
<li>Arithmetic operators</li>
<li>Assignment operators</li> - Arithmetic operators
<li>Comparison operators</li> - Assignment operators
<li>Increment/Decrement operators</li> - Comparison operators
<li>Logical operators</li> - Increment/Decrement operators
<li>String operators</li> - Logical operators
<li>Array operators</li> - String operators
</ul> - Array operators
<h3>PHP Arithmetic Operators</h3>
<p>The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.</p> ### PHP Arithmetic Operators
<table> The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.
<tr>
<th>Operator</th> Operator | Name | Example | Result
<th>Name</th> -------- | -------------- | -------- | ---
<th>Example</th> \+ | Addition | $a + $b | Sum of $a and $b
<th>Result</th> \- | Subtraction | $a - $b | Difference of $a and $b
</tr> \* | Multiplication | $a * $b | Product of $a and $b
<tr> \/ | Division | $a / $b | Quotient of $a and $b
<td>+</td> \% | Modulus | $a % $b | Remainder of $a divided by $b
<td>Addition</td> \** | Exponentiation | $a ** $b | Result of raising $a to the $b'th power
<td>$a + $b</td>
<td>Sum of $a and $b</td> ### PHP Comparison Operators
</tr> The PHP comparison operators are used to compare two values
<tr>
<td>-</td> Operator | Name | Example | Result
<td>Subtraction</td> -------- | ------------------------ | --------- | ---
<td>$a - $b</td> == | Equal | $a == $b | Returns **true** if $a is equal to $b
<td>Difference of $a and $b</td> === | Identical | $a === $b | Returns **true** if $a is equal to $b, and they are the same type
</tr> != | Not equal | $a != $b | Returns **true** if $a is not equal to $b
<tr> <> | Not equal | $a <> $b | Returns **true** if $a is not equal to $b
<td>*</td> !== | Not identical | $a !== $b | Returns **true** if $a is not equal to $b, or they are different types
<td>Multiplication</td> \> | Greater than | $a > $b | Returns **true** if $a is greater than $b
<td>$a * $b</td> \< | Less than | $a < $b | Returns **true** if $a is less than $b
<td>Product of $a and $b</td> \>= | Greater than or equal to | $a >= $b | Returns **true** if $a is greater than or equal to $b
</tr> \<= | Less than or equal to | $a <= $b | Returns **true** if $a is less than or equal to $b
\<=> | Spaceship | $a <=> $b | Returns an **integer** less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b.
<tr>
<td>/</td> **Note:** Spaceship operator is available as of PHP 7+
<td>Division</td> #### Spaceship example
<td>$a / $b</td> ```php
<td>Quotient of $a and $b</td> echo 1 <=> 0; // returns 1
</tr> echo 1 <=> 1; // returns 0
<tr> echo 1 <=> 2; // returns -1
<td>%</td> ```
<td>Modulus</td>
<td>$a % $b</td> #### More Information:
<td>Remainder of $a divided by $b</td> - <a href='http://php.net/manual/en/language.operators.arithmetic.php' target='_blank' rel='nofollow'>Arithmetic Operators</a></li>
</tr> - <a href='http://php.net/manual/en/language.operators.assignment.php' target='_blank' rel='nofollow'>Assignment Operators</a></li>
<tr>
<td>**</td>
<td>Exponentiation</td>
<td>$a ** $b</td>
<td>Result of raising $a to the $b'th power </td>
</tr>
</table>
### PHP Assignment Operators
The assignment operator is `=`. The operand on the left side gets assigned the value of the expression on the right.
#### Example
```php
<?php
$a = 7; // $a set to 7.
?>
```
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
- <a href='http://php.net/manual/en/language.operators.arithmetic.php' target='_blank' rel='nofollow'>Arithmetic Operators</a></li>
- <a href='http://php.net/manual/en/language.operators.assignment.php' target='_blank' rel='nofollow'>Assignment Operators</a></li>