Day -3 Bhavik PHP Operators like Arithmetic Operators , Assignment Operators ,Comparison Operators , Logical Operators
Arithmetic operators
PHP features arithmetic operatorSymbol | Name | Example | Result |
---|---|---|---|
+ | addition | echo 7 + 5 | 12 |
- | subtraction | echo 7 - 5 | 2 |
* | multiplication | echo 7 * 5 | 35 |
/ | division | echo 7 / 5 | 1.4 |
% | modulus | echo 7 % 5 | 2 |
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
Symbol | Name | Usage | Result |
---|---|---|---|
== | equal to | a == b | true if a equals b, otherwise false |
!= | not equal to | a != b | true if a does not equal b, otherwise false |
=== | identical to | a === b | true if a equals b and they are of the same type, otherwise false |
!== | not identical to | a !== b | true if a does not equal b or they are not of the same type, otherwise false |
< | less than | a < b | true if a is less than b, otherwise false |
> | greater than | a > b | true if a is greater than b, otherwise false |
<= | less than or equal to | a <= b | true if a is less than or equal to b, otherwise false |
>= | greater than or equal to | a >= b | true if a is greater than or equal to b, otherwise false |
Logical operators
PHP logical operators:
Symbol | Name | Example | Result |
---|---|---|---|
&& | and | a && b | true if a and b are true , otherwise false |
and | and | a and b | true if a and b are true , otherwise false |
|| | or | a || b | true if a or b are true , otherwise false |
or | or | a or b | true if a or b are true , otherwise false |
xor | xor | a xor b | true if a or b — but not both — are true , otherwise false |
! | not | !a | true 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;
sub ='.$q;
$r=5;
$r*=5;
echo '
mult='.$r;
mult='.$r;
$s=5;
$s/=5;
echo '
div='.$s;
div='.$s;
----------------------------------------------------
Output:-
sum = 6
sub =4
mult=25
div=1
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