3v4l.org

run code in 300+ PHP versions simultaneously
<?php $p = 1; for ($i = 1; $i <= 3; $i++) { echo '$p before calculation: ' . $p . PHP_EOL; for ($k = 1; $k <= $i; $k++) { $p = $p * 3; } echo '$p after calculation: ' . $p . PHP_EOL; } echo '$p at end of script: ' . $p . PHP_EOL; echo '=====' . PHP_EOL; unset($p); // just for having both examples at once for ($i = 1; $i <= 3; $i++) { $p = 1; echo '$p before calculation: ' . $p . PHP_EOL; for ($k = 1; $k <= $i; $k++) { $p = $p * 3; } echo '$p after calculation: ' . $p . PHP_EOL; } echo '$p at end of script: ' . $p . PHP_EOL;
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
$p before calculation: 1 $p after calculation: 3 $p before calculation: 3 $p after calculation: 27 $p before calculation: 27 $p after calculation: 729 $p at end of script: 729 ===== $p before calculation: 1 $p after calculation: 3 $p before calculation: 1 $p after calculation: 9 $p before calculation: 1 $p after calculation: 27 $p at end of script: 27

preferences:
58.46 ms | 407 KiB | 5 Q