mercredi 26 septembre 2018

Correct Operator to echo $result statement with multiple operators PHP

The homework goes as follows:

Create 2 variables, with values 10, 12.

Write 5 individual PHP statements that compares the 2 variables using the following comparison operators

Less Than, <

Less than or Equal to, <=

Greater than, >

Greater than or Equal to, >=

Not Equal to, !=

If the comparison value is TRUE, echo a string statement that describes the results of the comparison. Examples:

$a = 10; $b=12; if ($a < $b) { echo "$a is less than $b
";}

Display the $result value using an echo statement.

   <?php

       $varOne = 10;

       $varTwo = 12;

       $lessThan = $varOne < $varTwo;

       $lessThanEqualTo = $varOne <= $varTwo;

       $greaterThan = $varOne > $varTwo;

       $greaterThanEqualTo = $varOne >= $varTwo;

       $notEqualTo = $varOne != $varTwo;

       $result = "$varOne"." "."is"." "."less"." "."than"." 
        "."$varTwo"." <br>";

       if ($varOne < $varTwo)
       { echo $result ;}

       else 
       { echo "$varOne is NOT less than $varTwo <br>";}

       if ($varOne <= $varTwo)
       { echo "$varOne is less than or equal to $varTwo <br>";}

       else 
       { echo "$varOne is NOT less than or equal to $varTwo <br>";}

       if ($varOne > $varTwo)
       { echo "$varOne is greater than $varTwo <br>";}

       else
       { echo "$varOne is NOT greater than $varTwo <br>";}

       if ($varOne >= $varTwo)
       { echo "$varOne is greater than or equal to $varTwo <br>";}

       else
       { echo "$varOne is NOT greater than nor equal to $varTwo <br>";}

       if ($varOne != $varTwo)
       { echo "$varOne is not equal to $varTwo <br>";}

       else 
       {  echo "$varOne IS equal to $varTwo <br>";}

   ?>

What I want to know is how to make the if statement only have echo $result but have the exact statement needed for the correct operation

Aucun commentaire:

Enregistrer un commentaire