PHP - Exemple d'opérateur conditionnel

Essayez l'exemple suivant pour comprendre l'opérateur conditionnel. Copiez et collez le programme PHP suivant dans le fichier test.php et conservez-le dans la racine du document de votre serveur PHP et parcourez-le à l'aide de n'importe quel navigateur.

<html>
   
   <head>
      <title>Arithmetical Operators</title>
   </head>
   
   <body>
   
      <?php
         $a = 10;
         $b = 20;
         
         /* If condition is true then assign a to result otheriwse b */
         $result = ($a > $b ) ? $a :$b;
         
         echo "TEST1 : Value of result is $result<br/>";
         
         /* If condition is true then assign a to result otheriwse b */
         $result = ($a < $b ) ? $a :$b;
         
         echo "TEST2 : Value of result is $result<br/>";
      ?>
   
   </body>
</html>

Cela produira le résultat suivant -

TEST1 : Value of result is 20
TEST2 : Value of result is 10