Skip to main content

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?

Comments

  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
  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,"
    ";
    ?>

    ReplyDelete
  10. $unit_consumed=200;
    $unit_price=5;
    $total_consumption=($unit_consumed)*($unit_price);
    echo $total_consumption;

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Popular posts from this blog

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...