fork download
  1. <?php
  2.  
  3.  
  4. $x=3;
  5. $y=4;
  6. $power=1;
  7.  
  8. for($i=1;$i<=$y;$i++)
  9. $power=$power*$x;
  10. echo $x.' raised to the power '.$y.' = '.$power;
  11.  
  12. // improved by Tempérance K.
  13. $Nx = 3;
  14. $Ny = 4;
  15. $Npower = 1;
  16.  
  17.  
  18. echo "\n\n--------------------------------------\n\n";
  19.  
  20. // Boucle for qui calcule la valeur de Nx puissance i puis multiplie power par résultat de calcul précédent
  21. for ($i = 1; $i <= $Ny; $i++) {
  22. $Nresult = pow($Nx, $i); // Equivaut à faire "Nx * Nx * "...$i fois"
  23. $Npower *= $Nresult;
  24. echo "$Nx raised to the power of $Ny equals $Npower";
  25. echo "\n";
  26. }
Success #stdin #stdout 0.03s 25976KB
stdin
Standard input is empty
stdout
3 raised to the power 4 = 81

--------------------------------------

3 raised to the power of 4 equals 3
3 raised to the power of 4 equals 27
3 raised to the power of 4 equals 729
3 raised to the power of 4 equals 59049