Operator Concept in PHP

11

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?
Tags

إرسال تعليق

11تعليقات

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 ";
    }

    ردحذف
  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";
    }

    ?>

    ردحذف
  3. ";
    echo "Consumption is - $consumption

    ";

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

    ردحذف
  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";

    ردحذف
  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";

    ردحذف
  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;

    ردحذف
  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;

    ردحذف
  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");

    ردحذف
  9. $a=13;
    echo ++$a, "
    "; //preincrement 14
    echo $a++, "
    "; // post increment 14
    echo $a--, "
    "; // post decrement 15
    echo $a--, "
    "; // post decrement 14
    echo $a++, "
    "; // post increment 13
    echo $a--, "
    "; // post decrement 14
    echo $a--, "
    "; // post decrement 13
    echo --$a, "
    ","
    ","
    "; // pre decrement 11


    $b=4;
    $a=5;
    //pre increment ++$a
    echo ++$a, "
    "; // 6,6
    echo ++$a, "
    "; // 7, 7
    echo ++$a, "
    "; // 8 ,8
    echo ++$a, "
    "; // 9 , 9
    echo ++$a, "
    "; // 10, 10
    echo ++$a, "
    "; // 11, 11
    echo ++$a, "
    "; // 12, 12
    echo ++$a, "
    ","
    "; // 13 , 13


    $b=4;
    $a=5;
    // post increment $a++
    echo $a++, "
    "; // 5,6
    echo $a++, "
    "; // 6,7
    echo $a++, "
    "; // 7,8
    echo $a++, "
    "; // 8,9
    echo $a++, "
    "; // 9,10
    echo $a++, "
    "; // 10,11
    echo $a++, "
    ","
    "; // 11,12


    $b=4;
    $a=5;
    // Pre decrement --$a
    echo --$a, "
    "; // 4,4
    echo --$a, "
    "; // 3,3
    echo --$a, "
    "; // 2,2
    echo --$a, "
    "; // 1,1
    echo --$a, "
    "; // 0,0
    echo --$a, "
    "; // -1,-1
    echo --$a, "
    "; // -2,-2


    $b=4;
    $a=5;
    // Post decrement $a--
    echo $a--, "
    "; // 5,4
    echo $a--, "
    "; // 4,3
    echo $a--, "
    "; // 3,2
    echo $a--, "
    "; // 2,1
    echo $a--, "
    "; // 1,0
    echo $a--, "
    "; // 0,-1
    echo $a--, "
    ","
    "; // -1,-2


    $a=5;
    $b=5;
    $a++; //5,$a=6
    ++$b; //6,$b=6
    echo $a++," ", ++$b,"
    ";
    ?>

    ردحذف
  10. $unit_consumed=200;
    $unit_price=5;
    $total_consumption=($unit_consumed)*($unit_price);
    echo $total_consumption;

    ردحذف
إرسال تعليق