Operators With Examples In PHP Programming

PHP Operators With Examples And Programms
\\ If you have any query or questions on my post, then please comment below //

Operators In PHP:  
Following are the operators of PHP:

Arithmetic Operators With Example In PHP:
In php language, we can do all arithmetic operators as we do in other language.
Operators Are: +, -, *, /, %. 
Program: Write a program to perform addition, subtract, multiplication, division, module division.
<?php
$num1 = 10;
$num2 = 20;
$addition = $num1+$num2;
echo"Addition Of Two Numbers is ="; 
echo $addition;

$subtraction = $num2 - $num1;
echo"Subtraction Of Two Numbers is ="; 
echo $subtraction;








$multiply=$num1*$num2;
echo"Multiplication of two numbers is = ";
echo $multiply;

$division=$num2/$num1;
echo"Division of two numbers is = ";
echo $division;

$moduledivision = $num2%$num1;
echo"Module Division Of Two Number is = ";
$moduledivision;
?>


Assignment Operators With Examples In PHP:
Operator        Another Way                      Description 
A = b                    a = b                          Here value of b is going to shift in a.          
a += b                   a = a + b                     Addition
a -= b                   a = a - b                      Subtraction
a *= b                   a = a * b                     Multiplication
a /= b                    a = a / b                      Division
a %= b                  a = a % b                    Modulus


Write a program to perform string operators in php.

 <?php
$a=10;
echo $a;

$b=20;
$b += 100;
echo $b;

$c=50;
$c -= 25;
echo $c;

$d=5;
$d *= 6;
echo $d;

$e=10;
$e /= 5;
echo $e;

$f=15;
$f %= 4;
echo $f;
?>


Please run this program and see the output and write output below the comment box.


String Operators With Example In PHP:
Operator   Name                    Example                                      Result
 .               Concatenation         $a = "Technical"

                                                     $b = $a . " Programming"       Now $b contains "Technical Programming"
.=             Concatenation            
$a = "Technical"
                 Assignment                $a .= "Programming"                 Now $a contains "Technical Programming"


Increment / Decrement Operators With Example In PHP:
Operators       Name                                 Description
++$a               Pre-increment           First Increase $a by one, then returns the value of $a
$a++               Post-increment         First returns $a value, then do increment $a by one
--$a                Pre-decrement          First decrements $a by one, then returns value of  $a.
$a--                Post-decrement         First returns the value of $a, then decrease the value of $a by one. 





Write a program to perform increment and decrement operation.
<?php
$a=100;
echo ++$a;

 // outputs 101

$b=20;
echo $b++;

 // outputs 20

$c=50;
echo --$c; 

// outputs 49

$d=12;
echo $d--; 

// outputs 12
?>



Comparison Operators With Example In PHP:
Operator     Name                    Example             Result With Description
==                Equal                       $a == $b            True if $a is equal to $b.
===             Identical                   $a === $b          True if $a is equal to $b, and they are of the same type.
!=                Not equal                 $a != $b             True if $a is not equal to $b.
<>               Not equal                  $a <> $b             True if $a is not equal to $b.
!==              Not identical             $a !== $b           True if $a is not equal to $b.

>                Greater than               $a > $b             True if $a is greater than $b.
<                Less than                   $a < $b              True if $a is less than $b.
>=            Greater than equal to    $a >= $b           True if $a is greater than or equal to $b.
<=            Less than or equal to     $a <= $b          True if $a is less than or equal to $b.



Logical Operators With Example In PHP:
Operator      Name          Example                 Result

and                 And            $a and $b               True if both $a and $b are true.
or                     Or              $a or $b                True if either $a or $b is true.
xor                   Xor             $a xor $b              True if either $a or $b is true, but not both true.
&&                  And            $a && $b             True if both $a and $b are true.
||                       Or                $a || $b               True if either $a or $b is true.
!                       Not                  !$a                  True if $a is not true.




Array Operators With Example In PHP:
Operator     Name               Example               Result
+                  Union                 $a + $b                Union of $a and $.

==               Equality               $a == $b             True if $a and $b have the same key or value pair.
===             Identity                $a === $b          True if $a and $b have the same key or value pairs in the 

                                                                          same order and of the same types
!=                Inequality            $a != $b               True if $a is not equal to $b
<>               Inequality            $a <> $b              True if $a is not equal to $b
!==             Non-identity        $a !== $b             True if $a is not identical to $b






 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail :

Labels: