PHP Tutorials 6: PHP Operators 2
Previously we have learnt about some of the PHP Operators, this article is continuance of the article “PHP Tutorials 5: PHP Operator“.
This operators are used to increment or decrement variables’ values. Concentrate on the example below with the description inside:
$x++; //this code is same to this: $x = $x + 1;
$x--; //this code is same to this: $x = $x - 1;
Most of the strict type programming languages are having two types of increment or decrement:
- Post-Increment / Decrement
- Pre-Increment /Decrement
As above Post-increment/decrement and Pre-Increment/Decrement both are Operators and add or subtract variables’ values but there are some situations based differences between these two types (Post and Pre). Look at the example below and the description:
$x = 1;
echo ++$x; // first increases the value of $x and then prints. so this will print 2;
echo $x++; //this will print 2 and then increase 1 unit. so for next "echo" 3 will be printed.
|++$x||Pre-Increment||Increments $x by one, then returns $x|
|$x++||Post-Increment||Returns $x, then increments $x by one|
|–$x||Pre-Decrement||Decrements $x by one, then returns $x|
|$x–||Post-Decrement||Returns $x, then decrements $x by one|
these operators are used to compare two values of the same data type (number / string). Comparison operators response with True or False after comparison.
|==||Equal||$x == $y||Returns true if $x is equal to $y|
|===||Identical||$x === $y||Returns true if $x is equal to $y, and they are of the same type|
|!=||Not equal||$x != $y||Returns true if $x is not equal to $y|
|<>||Not equal||$x <> $y||Returns true if $x is not equal to $y|
|!==||Not identical||$x !== $y||Returns true if $x is not equal to $y, or they are not of the same type|
|>||Greater then||$x > $y||Returns true if $x is greater than $y|
|<||Less then||$x < $y||Returns true if $x is less than $y|
|>=||Greater then or equal to||$x >= $y||Returns true if $x is greater than or equal to $y|
|<=||Less then or equal to||$x <= $y||Returns true if $x is less than or equal to $y|
String, Array and Logical Operators will be discussed in the next tutorial. be with codejow.com and learn the way to code!