Day -3 Bhavik PHP Operators like Arithmetic Operators , Assignment Operators ,Comparison Operators , Logical Operators

Arithmetic operators

PHP features arithmetic operator

SymbolNameExampleResult
+additionecho 7 + 512
-subtractionecho 7 - 52
*multiplicationecho 7 * 535
/divisionecho 7 / 51.4
%modulusecho 7 % 52

Comparison operators

PHP's comparison operators compare 2 values, if the comparison succee producing a Boolean result of true, or false if it failed. you are use with if...else and while loop etc.
PHP comparison operators

SymbolNameUsageResult
==equal toa == btrue if a equals b, otherwise false
!=not equal toa != btrue if a does not equal b, otherwise false
===identical toa === btrue if a equals b and they are of the same type, otherwise false
!==not identical toa !== btrue if a does not equal b or they are not of the same type, otherwise false
<less thana < btrue if a is less than b, otherwise false
>greater thana > btrue if a is greater than b, otherwise false
<=less than or equal toa <= btrue if a is less than or equal to b, otherwise false
>=greater than or equal toa >= btrue if a is greater than or equal to b, otherwise false

Logical operators


PHP logical operators:

SymbolNameExampleResult
&&anda && btrue if a and b are true, otherwise false
andanda and btrue if a and b are true, otherwise false
||ora || btrue if a or b are true, otherwise false
orora or btrue if a or b are true, otherwise false
xorxora xor btrue if a or b — but not both — are true, otherwise false
!not!atrue if a is false; false if a is true

Assignment operators

$p=5;
$p+=1;
echo 'sum = '.$p;

$q=5;
$q-=1;
echo '
sub ='.$q;

$r=5;
$r*=5;
echo '
mult='.$r;

$s=5;
$s/=5;
echo '
div='.$s;
----------------------------------------------------
Output:-

sum = 6
sub =4
mult=25
div=1
************************************************
If you competed these all task so now you code review these example like Calculator,
value is odd than or even than,
value is positive or negative
so download these example and review of code...

1. Calculator...........

........Download

2. Value is odd or even than....

........Download

3. Value is positive or negative.....

........Download

0 comments:

Post a Comment

Newer Post Older Post Home