Thursday, February 28, 2013

Operators in PHP 5.4.8

Operators in PHP 5.4.8





Airthmetic   Operators


OperatorDescriptionExampleOutput
+Additionex1: $i=1+1; $j=1.5+1.23; $k=$i+$j;2 2.73 4.73
-Minusex1: $i=1-1; $j=1.5-1.23; $k=$i+$j;0, 0.27, 0.27
*Multiplicationex1: $i=10*10; $j=1.5*1.23; $k=$i*$j;100, 1.845, 184.5
/Divisionex1: $i=1/2; $j=1.5/1.23; $k=$i/$j;0.5; 1.219512195122; 0.41
%Modulusex1:$i=8%2; $j=1.5%5.5; $k=$i%$j;0 ,1, 0
++Incrementex1: $i++; ++$j; $k=$i++ + $j++;3,4,5  (i=1,j=2)
--Decrementex1: $i--; --$j; $k=$i-- + $j--;-1, 0; 1(i=1,j=2)


Logical Operators



OperatorDescriptionExampleOutput
&&Andex1: $i=1;$j=2 ; $i==1 && $j==2true
andlow-precedence and ex1: $i=1;$j=2 ; $i==1 and $j==2true
||Orex1: $i=1;$j=2 ; $i==1 || $j==2true (it never evaluate $j==2)
because first exp is true.
orlow-precedence orex1: $i=1;$j=2 ; $i==1 or $j==2same as above ||
!Not$i=1;$j=2 ; !($i==$j)true
xorExclusive orex1: $i=1;$j=2; $i xor $j1


Comparison Operators/Relational Operators.


OperatorDescriptionExampleOutput
==is equal toex1: $i=1; $j=2; $i==$j;  false
!=not equal toex1: $i=1;$j=2; $i != $jtrue
>is greater thanex1: $i=10; $j=20; $i>$jfalse
<is less thanex1: $i=10;$j=20; $i<$jtrue
>=is greater than equal toex1:$i=8;$j=8.8; $i >= $j
false
<=is less than equal toex1: $i=8;$j=8.8; $i <= $j
true