3v4l.org

run code in 300+ PHP versions simultaneously
<?php function add($stack, $nb1, $nb2) { array_push($stack, $nb1 + $nb2); $result = $nb1 + $nb2; echo $nb1 . ' + ' . $nb2 . ' = ' . $result . "\n"; } function sub($stack, $nb1, $nb2) { array_push($stack, $nb1 - $nb2); $result = $nb1 - $nb2; echo $nb1 . ' - ' . $nb2 . ' = ' . $result . "\n"; } function div($stack, $nb1, $nb2) { array_push($stack, $nb1 / $nb2); $result = $nb1 / $nb2; echo $nb1 . ' / ' . $nb2 . ' = ' . $result . "\n"; } function mul($stack, $nb1, $nb2) { array_push($stack, $nb1 * $nb2); $result = $nb1 * $nb2; echo $nb1 . ' * ' . $nb2 . ' = ' . $result . "\n"; } function calc($input) { $stack = array(); $token = explode(" ", trim($input)); $count = count($token); // echo $count . "\n"; // print_r($token); for ($i = 0; $i < $count; $i++) { $tokenNUm = ""; if (is_numeric($token[$i])) { array_push($stack, $token[$i]); print_r($token); } else { $nb2 = end($stack); array_pop($stack); $nb1 = end($stack); array_pop($stack); echo "nb1 : ". $nb1 . "\n"; echo "nb2 : ". $nb2 . "\n"; switch($token[$i]) { case '+': add($stack, $nb1, $nb2); break; case '-': sub($stack, $nb1, $nb2); break; case '/': div($stack, $nb1, $nb2); break; case '*': mul($stack, $nb1, $nb2); break; default: die('Error'); } } } return end($stack); } $argv[1] = "1 + 2"; echo "Final result = " . calc($argv[1]) . "\n";
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 1 [1] => + [2] => 2 ) nb1 : nb2 : 1 + 1 = 1 Array ( [0] => 1 [1] => + [2] => 2 ) Final result = 2

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.45 ms | 401 KiB | 8 Q