Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php
  2.     $saisie = 1+1;2*2;3/3; // 7
  3.  
  4.     $chiffres = explode(';',$saisie);
  5.     for($i=0;$i<count($chiffres);$i++)
  6.     {
  7.         $addition = strpos("+",$chiffres[$i]);
  8.         $soustraction = strpos("-",$chiffres[$i]);
  9.         $multiplication = strpos("*",$chiffres[$i]);
  10.         $division = strpos("/",$chiffres[$i]);// 1+1
  11.        
  12.         if(is_numeric($addition)) // si c'est un chiffre OU if($addition!=false)
  13.         {
  14.             $operation = explode("+",$chiffres[$i]);
  15.             $resultat = $operation[0]+$operation[1];
  16.             // 1) Je veux sue tu fasses un explode() du caractère en question :
  17.             /*
  18.                 C'est à dire que si j'ai trouvé un "+", alors tu vas faire un $operation = explode("+",$chiffres[$i])
  19.                
  20.                 ton premier chiffre => $operation[0] ;
  21.                 ton deuxieme chiffre => $operation[1];
  22.                
  23.                 $resultat = $operation[0] + ....
  24.             */
  25.         }
  26.        
  27.         if(is_numeric($soustraction))
  28.         {
  29.             $operation = explode("-",$chiffres[$i]);
  30.             $resultat = $operation[0]-$operation[1];
  31.         }// Pareil pour les trois autres
  32.        
  33.         if(is_numeric($multiplication))
  34.         {
  35.             $operation = explode("*",$chiffres[$i]);
  36.             $resultat = $operation[0]*$operation[1];
  37.         }
  38.        
  39.         if(is_numeric($division))
  40.         {
  41.             $operation = explode("/",$chiffres[$i]);
  42.             $resultat = $operation[0]/$operation[1];
  43.         }
  44.        
  45.             echo "Le resultat est de $resultat ";
  46.     }
  47. ?>
Add Comment
Please, Sign In to add comment