Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Operator Concept in PHP:-
..............................................................................



It is used to perform operations using operand, Operand can be variable, constant, and literals.

literal means value of variable or constant. for example, 1 is literals, "hello" is String literals.


Type of Operator:-

1) Unary:-    This operator will work using a single operand.

1.1 Increment:-      $a++    increase by one

1.1.1  Post increment:-   first complete other operation then increase value.
          $a++;

         Example of Post Increment:-
         <?php
             $a=2;
            $b=$a++;  //b=2,a=3
            echo $a,"<br>",$b;
          ?>
   
1.1.2  Pre Increment:-     first increase then perform other operations.

         ++$a;

1.2  Decrement:-   $a--      decrease by one
   
Example of Increment, Decrement:-

<?php

$a=5;
$a++;
echo $a,"<br>";
$a--;
echo $a;

?>


Another Example of Increment, Decrement:-

<?php

$a=5;
$b=5;
$a++;  
++$b;
echo $a++ ," ", ++$b,"<br>";

?>


2) Binary:-   It will use minimum two operand to perform operation .

2.1) Arithmetic :-  +,-,*,/, %

2.2)  Conditional or Relational :-   <, >,  <=,  >=    (it will use in if--else or loop)

2.3)  Comparison  :-

         ==      it will compare only data, datatype can be different

         if(2=="2")   //true
    
        ===   it will compare data and datatype both
       if(2==="2")   //false

2.4)  Logical Operator:-

       &&       it will return when all condition will be true

       ||            it will return when the particular condition will be true

      !             it is the opposite of true condition and returns a false value.

2.5) Assignment operator:-

2.5.1)   Simple Assignment    =    ($a=2 )
2.5.2)   Complex Assignment      $a=$a+5  ,  $a+=5
                                                      $a=$a*3,   $a*=3

                                                     $a=$a/4       $a/=4

<?php
$a=5;      //5
$a=$a+2;   //7
echo $a;
$a=$a*2;   //14
echo $a;
$a=$a%2;  
echo $a;  //0

?> 

3) Ternary:-

It is used to solve the condition-based problems using a ternary statement. ternary provide a single-line statement to implement code.

var = (condition)?true:false;

WAP to check even numbers or odd numbers?

<?php
$num=4;
echo $num%2==0?"even":"odd";



?>


<?php
$num=4;
$x=$num%2==0?"even":"odd";
echo $x;


?>


Assignment:-

WAP to calculate electricity bill where unit price and total consumption will be assigned by the user?

WAP to reverse the five-digit number?

12345   res  54321

<?php
$num = 78912;

$a = $num%10;  //5
$num = (int)($num/10); //1234.5
$b = $num%10;  //4
$num = (int)($num/10);  //123
$c = $num%10; //3
$num = (int)($num/10);  //12
$d = $num%10;  //2
$e = (int)($num/10);  //1
$rev = $a*10000+$b*1000+$c*100+$d*10+$e*1;
print($rev);

?>





 WAP to perform the addition of complex numbers?

2+3i
4+5i
.................
6+8i

<?php

$r1=2;
$i1=4;
$r2=7;
$i2=5;
$r = $r1+$r2;
$i = $i1+$i2;

echo $r1."+".$i1."i"."<br>";
echo $r2."+".$i2."i"."<br>";
echo $r."+".$i."i";

?>


Another Solution:-

<?php

$r1=2;
$i1=4;
$r2=7;
$i2=5;
$r = $r1+$r2;
$i = $i1+$i2;

echo "$r1 + $i1 i <br>";
echo "$r2 + $i2 i <br>";
echo "$r + $i i <br>";

?>



WAP to calculate the salary of the employee where basic, ta, da, comm, pf,hra, and leave will be assigned by the users?







8 Comments

POST Answer of Questions and ASK to Doubt

  1. Kritika Barod

    =100&&$unit<=200)
    {
    $bill=$unit*20;
    echo "bill is =$bill";
    }
    else if ($unit>=200&&$unit<=300)
    {
    $bill=$unit*30;
    echo "bill is =$bill ";
    }

    ReplyDelete
  2. MANSI DUBEY


    100 && $unit<=200)
    {
    $bill=$unit*40;
    echo "$bill";
    }
    elseif ($unit>200 && $unit<=300)
    {
    $bill=$unit*60;
    echo "$bill";
    }
    else
    {
    $bill=$unit*80;
    echo "$bill";
    }

    ?>

    ReplyDelete
  3. ";
    echo "Consumption is - $consumption

    ";

    echo "Electricity bill is - $bill";
    ?>

    ReplyDelete
  4. $leaves_days=2;

    $basic=100000;
    $ta=$basic*.20;
    $da=$basic*.10;
    $comm=9000;
    $pf=($basic*12)/100;
    $hra=$basic*.40;

    $leaves=3333.33*$leaves_days;

    $salary=$basic+$ta+$da+$pf+$hra+$comm-$leaves;

    echo "Salary of the month is = "." $salary";

    ReplyDelete
  5. Reverse 10 Digit Number

    $n=1234567591;
    $a=$n%10;
    $n=(int)($n/10);
    $b=$n%10;
    $n=(int)($n/10);
    $c=$n%10;
    $n=(int)($n/10);
    $d=$n%10;
    $n=(int)($n/10);
    $e=$n%10;
    $n=(int)($n/10);
    $f=$n%10;
    $n=(int)($n/10);
    $g=$n%10;
    $n=(int)($n/10);
    $h=$n%10;
    $n=(int)($n/10);
    $i=$n%10;
    $n=(int)($n/10);
    $j=$n%10;
    $num=$a*1000000000+$b*100000000+$c*10000000+$d*1000000+$e*100000+$f*10000+$g*1000+$h*100+$i*10+$j*1;
    echo"$num is reverse number";

    ReplyDelete
  6. Salary
    Shubham Nandwal

    //please enter basic,hra,leavedays,ta,da,pf,tax and el value//

    $basic=25000;
    $leavedays=5;
    $hra=7500;
    $ta=6000;
    $da=8000;
    $pf=3000;
    $el=900;

    //************************************************************//
    $proffesionaltax=950;
    $grosssalary=$basic+$hra+$ta+$da+$el;
    $netsalary=($grosssalary)-($pf+$proffesionaltax);

    echo "
    ";
    echo "BASIC SALARY IS : " .$basic;
    echo "
    ";
    echo "GROSS SALARY IS : " .$grosssalary;
    echo "
    ";
    echo "TOTAL DEDUCTIONS IS : " .$pf+$proffesionaltax;
    echo "
    ";
    echo "NET SALARY IS : " .$netsalary;

    ReplyDelete
  7. Electricity Bill Programme

    Shubham Nandwal

    define('u',7.5);
    $pr=142023;
    $cr=142110;

    $con=$cr-$pr;
    $pay=$con*u;
    $d= "12-04-2021";
    $c= "10-04-2021";
    echo "
    ";
    echo "
    ";
    echo "Your Total Consumption of This Month Is ".$con ," UNIT ";
    echo "
    ";
    echo "Your Current Electricity Bill Is Rs. " .$pay;
    echo "
    ";
    echo "Last Date Of Payment By cash Is ".$d;
    echo "
    ";
    echo "Last Date of Payment By Cheque Is " .$c;

    ReplyDelete
  8. //WAP to calculate the salary of the employee where basic, ta, da, comm, pf,hra, and leave will be assigned by the users
    $basic=15000;
    $ta=2500;
    $da=3000;
    $comm=2000;
    $pf=12*($basic+$da)/100;
    $hra=5000;
    $leave=2;
    $Net_salary=$basic+$ta+$da+$comm+$hra-$pf-($basic*$leave)/30;
    echo "
    ";
    echo("Net salary of the employee is:-.$Net_salary");

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post