PHP Mathematical Expression

PHP Mathematical Expression

Arithmetic operators

Arithmetic operators are used in programming and mathematics to perform basic mathematical operations on numbers. These operators are fundamental in performing mathematical calculations and are commonly used in programming languages to manipulate numerical data.

  •                         <html>
                                <head>
                                    <title>PHP operators</title>
                                </head>
                                <body>
                                    <?php
                                         $x=5;//Variable declaration
                                         $y=10;//Variable declaration
                                     echo "Addition:".($x+$y)."<br>";//+Adds two operands to produce the sum of their values. For example, 2 + 3 equals 5.
                                     echo "Subtraction:".($x-$y)."<br>";//-Subtracts the second operand from the first operand to give the difference. For example, 7 - 4 equals 3.
                                     echo "Multiplication:".($x*$y)."<br>";//*Multiplies two operands together to produce their product. For example, 5 * 6 equals 30.
                                     echo "Division:".($x/$y)."<br>";//(/)divides one number by another and returns the quotient.
                                     echo "Modulus:".($x%$y)."<br>";//%Returns the remainder when the first operand is divided by the second operand. For example, 17 % 5 equals 2 
                                     echo "Exponent:".($x**$y)."<br>";//The ** operator raises a number to the power of another number.
                                    ?>
                                </body>
                             </html>
    

    Solution...

  • Assignment Operator

  • Assignment operators are used in programming to assign a value to a variable.

    Assignment operators are essential in storing and updating values in variables, enabling dynamic and interactive programming.

<html>
    <head>
        <title>Assignment operators</title>
    </head>
    <body>
    <?php
    echo "***Addition***"."<br>";//print statement with line break
     $b=10;//variable declaration
     echo "Before Appling Addition:".$b."<br>";//print statement
     $b+=50;//+= (Addition assignment operator): The addition assignment operator adds the value on the right side to the value of the variable on the left side, and then assigns the result back to the variable
     echo " After Appling Addition:".$b."<br>";//print statement
     echo "***Subtraction***"."<br>";//print statement with line break
     $b=10;//variable declaration
     echo "Before Appling Subtraction:".$b."<br>";//print statement
     $b-=50;//-= (Subtraction assignment operator): The subtraction assignment operator subtracts the value on the right side from the value of the variable on the left side, and then assigns the result back to the variable.
     echo " After Appling Subtraction:".$b."<br>";//print statement
     echo "***Multiplication***"."<br>";//print statement
     $b=10;////variable declaration
     echo "Before Appling Muliplication:".$b."<br>";//print statement
     $b*=50;//*=(Multiplication assignment operator): The multiplication assignment operator multiplies the value of the variable on the left side by the value on the right side, and then assigns the result back to the variable.
     echo " After Appling Multiplication:".$b."<br>";//print statement
     echo "***Division***"."<br>";//print statement
     $b=10;////variable declaration
     echo "Before Appling Division:".$b."<br>";//print statement
     $b/=50;///= (Division assignment operator): The division assignment operator divides the value of the variable on the left side by the value on the right side, and then assigns the result back to the variable.
     echo " After Appling Division:".$b."<br>";//print statement
     echo "***Modulus***"."<br>";//print statement
     $b=10;////variable declaration
     echo "Before Appling Modulus:".$b."<br>";//print statement
     $b%=50;//%= (Modulo assignment operator): The modulo assignment operator calculates the remainder of the division between the value of the variable on the left side and the value on the right side, and then assigns the result back to the variable.
     echo " After Appling Modulus:".$b."<br>";//print statement

    ?>

    </body>


</html>

Solution...

Comparison Operators

Comparison operators are used in programming and mathematics to compare two values and determine their relationship.These comparison operators are frequently used in programming to make decisions based on the relationship between values, such as in conditional statements or sorting algorithms.

<html>
    <head>
        <title>Comparison Operators</title>
    </head>
    <body>
    <?php
    echo"***Equal operator== using***"."<br>";                                                 //NO 1
     $a=5;//variable declaration                                                    
     $b=5;//variable declaration
     if($a==$b)//check condition equal or not equal
     {
        echo "value are equal";//print statement
     }
     else
     {
        echo "value are not equal";//print statement
     }
    echo "<br>";//Line break


     echo"*** using identical operator=== ***"."<br>";                                        //NO 2
     $a=5;//variable declaration
     $b=5.0;//variable declaration
     if($a===$b)//check condition equal and same data type
     {
        echo "value are identical";//print statement
     }
     else
     {
        echo "value are not identical";//print statement
     }
    echo"<br>";//linr braek


     echo"*** using NotEqual operator!= ***"."<br>";                                           //NO 3
     $a=5;//varibale declaraction
     $b=5;//variable declaraction
     if($a!=$b)//( you can also use <> both have same meaning)check condition not equal
     {
        echo "value are not equal";//print statement
     }
     else
     {
        echo "value are  equal";//print statement
     }
     echo"<br>";

     echo"*** using greaterthen operator> ***"."<br>";                                      //NO 4
     $a=5;//varibale declaraction
     $b=5;//variable declaraction
     if($a>$b)//check condition greater then
     {
        echo "value greater then";//print statement
     }
     else
     {
        echo "value not greater then";//print statement
     }
     echo"<br>";//line break

     echo"*** using greaterthen&equal operator<= ***"."<br>";                               //NO 5
     $a=5;//varibale declaraction
     $b=10;//variable declaraction
     if($a<=$b)//check statement less then and equal
     {
        echo " a is smaller then b";//print statement
     }
     else
     {
        echo "b is smaller the a";//print statement
     }
     echo"<br>";

     echo"*** using lessgthen&equal operator>= ***"."<br>";                                //NO 6
     $a=5;//varibale declaraction
     $b=10;//variable declaraction
     if($a>=$b)//check statement less then and equal
     {
        echo " a is greater then then b";//print statement
     }
     else
     {
        echo "b is greater then the a";//print statement
     }
     echo"<br>";
    ?>

    </body>


</html>

Solution...

Increment&Decrement Operators

Increment and decrement operators are used in programming to increment or decrement the value of a variable by a specific amount. It's important to note that using these operators can have side effects and should be used with caution to avoid unintended consequences, such as infinite loops or unexpected behavior in complex expressions.

  1. The increment operator (++) is used to increase the value of a variable by one. It can be written as variable++ or ++variable, and both forms have the same effect of incrementing the variable by 1.

  2. The decrement operator (--) is used to decrease the value of a variable by one. It can be written as variable-- or --variable, and both forms have the same effect of decrementing the variable by 1.

  3. These operators are commonly used in loops, such as for loops or while loops, to control the iteration and manipulate the counter variable.

<html>
    <head>
        <title>increment/decrement Operators</title>
    </head>
    <body>
    <?php
    $a=10;//variable declaraction
    echo "output with increment ".++$a;//pre increment
    echo"<br>";//line break
    echo "Output should be without increment: ".$a++;//post increment
    echo"<br>";//line break
    echo "Output should be with increment:".$a;
    echo"<br>";//line break

    $a=10;//variable declaraction
    echo "output with deccrement ".--$a;//pre decrement
    echo"<br>";//line break
    echo "Output should be without decrement: ".$a--;//post decrement
    echo"<br>";//line break
    echo "Output should be with decrement:".$a;
     ?>

    </body>


</html>

Solution...

LogicalOperator

  1. The AND operator (&&) returns true if both operands are true, and false otherwise.

  2. The OR operator (||) returns true if at least one of the operands is true, and false otherwise.

  3. The NOT operator (!) reverses the boolean value of its operand.

  4. These operators are commonly used to make decisions in conditional statements.

  5. Logical operators are fundamental tools for controlling program flow and evaluating conditions in programming.

    <html>
        <head>
            <title>my web</title>
        </head>
        <body>
           <form>
        <?php
        $a=10;//variable declaration & assigning value
        $b=5; //variable declaration & assigning value
            //AND operation...
             if($a==10 and $b==5)//check two conditions are equal or not            
             {
              echo"you can access";//print statement
             }
             else
             {
                 echo"Not access";//print statement
             }echo"<br>";

             //OR operation
              if($a==10 or $b==5)//one condition true is always true
             {
              echo"you can access";//print statement
             }
             else
             {
                 echo"Not access";//print statement
             }echo"<br>";

             //Xor operation
              if($a==10 Xor $b==10)// if both the situation is OK then you will get the False answer .if both the situation os False then you will get the Ok answer 
             {
              echo"you can access";//print statement
             }
             else
             {
                 echo"Not access";//print statement
             }echo"<br>";

            //Not equal  operation

            $x=10;//variable declaration & assigning value
            if($x!==10)//Check condition value not  equal
            {
                echo"You can access";//print statement
            }

    else
            {
                echo"Not access";//print statment
            }

        ?>


        </form>
        </body>




    </html>

Solution...