From ea700759fedc5a0a4c49553b76e1145b54dd93bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berat=20A=C5=9F=C4=B1c=C4=B1?= <4410500+torelafes@users.noreply.github.com> Date: Fri, 29 Mar 2019 02:27:09 +0300 Subject: [PATCH] Added Comparison Operators (#32078) Also removed HTML tags and wrote everything in markdown syntax --- guide/english/php/php-operators/index.md | 140 +++++++++-------------- 1 file changed, 56 insertions(+), 84 deletions(-) diff --git a/guide/english/php/php-operators/index.md b/guide/english/php/php-operators/index.md index fbba648aa0..ea6dec8ad3 100644 --- a/guide/english/php/php-operators/index.md +++ b/guide/english/php/php-operators/index.md @@ -1,84 +1,56 @@ ---- -title: PHP Operators ---- -## PHP Operators - -

Operators are used to perform operations on variables and values.

-

PHP divides the operators in the following groups:

- -

PHP Arithmetic Operators

-

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OperatorNameExampleResult
+Addition$a + $bSum of $a and $b
-Subtraction$a - $bDifference of $a and $b
*Multiplication$a * $bProduct of $a and $b
/Division$a / $bQuotient of $a and $b
%Modulus$a % $bRemainder of $a divided by $b
**Exponentiation$a ** $bResult of raising $a to the $b'th power
- -### 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 - -``` - - - -#### More Information: -- Arithmetic Operators -- Assignment Operators - +--- +title: PHP Operators +--- +## PHP Operators + +Operators are used to perform operations on variables and values. + +PHP divides the operators in the following groups: + +- Arithmetic operators +- Assignment operators +- Comparison operators +- Increment/Decrement operators +- Logical operators +- String operators +- Array operators + +### PHP Arithmetic Operators +The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. + +Operator | Name | Example | Result +-------- | -------------- | -------- | --- +\+ | Addition | $a + $b | Sum of $a and $b +\- | Subtraction | $a - $b | Difference of $a and $b +\* | Multiplication | $a * $b | Product of $a and $b +\/ | Division | $a / $b | Quotient of $a and $b +\% | Modulus | $a % $b | Remainder of $a divided by $b +\** | Exponentiation | $a ** $b | Result of raising $a to the $b'th power + +### PHP Comparison Operators +The PHP comparison operators are used to compare two values + +Operator | Name | Example | Result +-------- | ------------------------ | --------- | --- +== | Equal | $a == $b | Returns **true** if $a is equal to $b +=== | Identical | $a === $b | Returns **true** if $a is equal to $b, and they are the same type +!= | Not equal | $a != $b | Returns **true** if $a is not equal to $b +<> | Not equal | $a <> $b | Returns **true** if $a is not equal to $b +!== | Not identical | $a !== $b | Returns **true** if $a is not equal to $b, or they are different types +\> | Greater than | $a > $b | Returns **true** if $a is greater than $b +\< | Less than | $a < $b | Returns **true** if $a is less than $b +\>= | Greater than or equal to | $a >= $b | Returns **true** if $a is greater than or equal to $b +\<= | 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. + +**Note:** Spaceship operator is available as of PHP 7+ +#### Spaceship example +```php +echo 1 <=> 0; // returns 1 +echo 1 <=> 1; // returns 0 +echo 1 <=> 2; // returns -1 +``` + +#### More Information: +- Arithmetic Operators +- Assignment Operators