Search This Blog

Showing posts with label operators. Show all posts
Showing posts with label operators. Show all posts

arithmetic operators in php


                                    arithmetic operators in php : + , - , * , / , % , ++ , --


<?php


$a=10;


echo $a+10;


?>


output : 20



<?php


$a=10;


echo $a-10;


?>
output :0 


<?php


$a=10;


echo $a*10;


?>
output : 100

<?php


$a=10;


echo $a/10;


?>
output : 1

<?php


$a=10;


echo $a+10;


?>
output : 20


<?php


$a=10;


echo $a--;


?>
output : 10

<?php


$a=10;


echo $a++;


?>


output : 10




<?php


$a=10;


echo --$a;


?>
output :  9

<?php


$a=10;


echo ++$a;


?>


output : 11





logical operators in php

                                              logical operators in php :  && , || , !




<?php


$a=10;
$b=20;
if($a<15 && $b>15)
echo  "$a is less than 15 and $b is grater than 15";


?>
output : 10 is less than 15 and 20 is grater than 15






<?php



$a=10;
$b=20;
if($a<15 || $b<15)
echo  "$a is less than 15 and $b is grater than 15";


?>
output : 10 is less than 15 or 20 is grater than 15





<?php



$a=10;
$b=20;
if(!($a<15 && $b>15))
echo  "$a is less than 15 and $b is grater than 15";


?>
output : 


nothing to display , because , inner value is true and we apply ! to that so , the value of if statement is false







comparison operators in php

                                           comparison operators :   == , <= , >= , != , < , > 



<?php
$num1=10;
$num2='10';


if($num1==$num2)
echo "$num1 is equal to $num2";


?>
output : 


nothing to display , $num1 is integer and  $num2 is string , string is not equal to integer


<?php
$num1=10;
$num2=20;


if($num1==$num2)
echo "$num1 is equal to $num2";


?>
output : 


nothing to display , because both are not equal





<?php

$num1=10;
$num2=20;


if($num1<=$num2)
echo "$num1 is less than or equal to $num2";


?>
output : 10 is less than or equal to 20



<?php
$num1=10;
$num2=20;


if($num1>=$num2)
echo "$num1 is grater than or equal to $num2";


?>

output : 


nothing to display , because 10  is not grater than or equal to 20






<?php

$num1=10;
$num2=20;


if($num1!=$num2)
echo "$num1 is not equal to $num2";


?>
output : 10 is not equal to 20



<?php
$num1=10;
$num2=20;


if($num1<$num2)
echo "$num1 is less than to $num2";


?>
output : 10 is less than to 20





<?php

$num1=10;
$num2=20;


if($num1>$num2)
echo "$num1 is grater than $num2";


?>
output :
nothing to display , because10  is not grater than to 20
















assignment operators in php



                            assignment operators in php     :      = , += , -= , *= , /= , .= , %=

<?php

$num1=10;
$num2=20;
echo ('<br>'. $num1." " .$num2);
?>


output :10 20




<?php
$num1=10;
$num2=20;
echo ('<br>'.$num2+=$num1);
?>


output :
30 





<?php


$num1=10;
$num2=20;
echo ('<br>'.$num2-=$num1
);?>


output :
10



<?php


$num1=10;
$num2=20;
echo ('<br>'.$num2*=$num1);
?>


output :
200





<?php


$num1=10;
$num2=20;


echo ('<br>'.$num2/=$num1);?>

output :
2



<?php
$num1=10;
$num2=20;
echo ('<br>'.$num2.=$num1);?>


output :
2010




<?php

$num1=10;
$num2=20;
echo ('<br>'.$num2%=$num1);

?>

output :
0








Share Links

Related Posts Plugin for WordPress, Blogger...