PHP 5 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.
OperatorNameExampleResultShow it
+Addition$x + $ySum of $x and $yShow it »
-Subtraction$x - $yDifference of $x and $yShow it »
*Multiplication$x * $yProduct of $x and $yShow it »
/Division$x / $yQuotient of $x and $yShow it »
%Modulus$x % $yRemainder of $x divided by $yShow it »
**Exponentiation$x ** $yResult of raising $x to the $y'th power (Introduced in PHP 5.6) 

PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.
The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
AssignmentSame as...DescriptionShow it
x = yx = yThe left operand gets set to the value of the expression on the rightShow it »
x += yx = x + yAdditionShow it »
x -= yx = x - ySubtractionShow it »
x *= yx = x * yMultiplicationShow it »
x /= yx = x / yDivisionShow it »
x %= yx = x % yModulusShow it »

PHP Comparison Operators

The PHP comparison operators are used to compare two values (number or string):
OperatorNameExampleResultShow it
==Equal$x == $yReturns true if $x is equal to $yShow it »
===Identical$x === $yReturns true if $x is equal to $y, and they are of the same typeShow it »
!=Not equal$x != $yReturns true if $x is not equal to $yShow it »
<>Not equal$x <> $yReturns true if $x is not equal to $yShow it »
!==Not identical$x !== $yReturns true if $x is not equal to $y, or they are not of the same typeShow it »
>Greater than$x > $yReturns true if $x is greater than $yShow it »
<Less than$x < $yReturns true if $x is less than $yShow it »
>=Greater than or equal to$x >= $yReturns true if $x is greater than or equal to $yShow it »
<=Less than or equal to$x <= $yReturns true if $x is less than or equal to $yShow it »

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value.
The PHP decrement operators are used to decrement a variable's value.
OperatorNameDescriptionShow it
++$xPre-incrementIncrements $x by one, then returns $xShow it »
$x++Post-incrementReturns $x, then increments $x by oneShow it »
--$xPre-decrementDecrements $x by one, then returns $xShow it »
$x--Post-decrementReturns $x, then decrements $x by oneShow it »

PHP Logical Operators

The PHP logical operators are used to combine conditional statements.
OperatorNameExampleResultShow it
andAnd$x and $yTrue if both $x and $y are trueShow it »
orOr$x or $yTrue if either $x or $y is trueShow it »
xorXor$x xor $yTrue if either $x or $y is true, but not bothShow it »
&&And$x && $yTrue if both $x and $y are trueShow it »
||Or$x || $yTrue if either $x or $y is trueShow it »
!Not!$xTrue if $x is not trueShow it »

PHP String Operators

PHP has two operators that are specially designed for strings.
OperatorNameExampleResultShow it
.Concatenation$txt1 . $txt2Concatenation of $txt1 and $txt2Show it »
.=Concatenation assignment$txt1 .= $txt2Appends $txt2 to $txt1Show it »

PHP Array Operators

The PHP array operators are used to compare arrays.
OperatorNameExampleResultShow it
+Union$x + $yUnion of $x and $yShow it »
==Equality$x == $yReturns true if $x and $y have the same key/value pairsShow it »
===Identity$x === $yReturns true if $x and $y have the same key/value pairs in the same order and of the same typesShow it »
!=Inequality$x != $yReturns true if $x is not equal to $yShow it »
<>Inequality$x <> $yReturns true if $x is not equal to $yShow it »
!==Non-identity$x !== $yReturns true if $x is not identical to $yShow it »


Credit: www.w3schools.com
PHP 5 Operators PHP 5 Operators Reviewed by webmission on 12:56 Rating: 5

No comments:

Powered by Blogger.