3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allowed_operators = array("*", "/", "^", "+", "-"); $rpn = "3 4 5 * -"; $rpnlen = strlen($rpn) - 1; $stack = array(); function digit($char) { return ctype_digit((string)$char); } //set_time_limit(2); function r_old() { global $pos, $rpn, $rpnlen, $stack, $allowed_operators, $result; if($rpnlen <= $pos) return false; $pos++; if($rpn[$pos] != ' ') { $tmp = ""; if(digit($rpn[$pos])) { while(digit($rpn[$pos]) || $rpn[$pos] == ".") { $tmp .= $rpn[$pos]; $pos++; } $pos--; if (!empty($tmp)) array_push($stack, $tmp); } else if(in_array($rpn[$pos], $allowed_operators)) { $second = array_pop($stack); $first = array_pop($stack); if($rpn[$pos] == '^') $result = eval("return pow($first, $second);"); else $result = eval("return ($first $rpn[$pos] $second);"); array_push($stack, $result); return r_old(); } else { return r_old(); } } return r_old(); } $result = 0; $pos = 0; function r() { global $pos, $rpn, $rpnlen, $allowed_operators, $result, $stack; while($rpn[$pos] == ' ') $pos++; if($rpnlen <= $pos) return false; if(digit($rpn[$pos])) { $tmp = ""; do { $tmp .= $rpn[$pos]; $pos++; } while(digit($rpn[$pos]) || $rpn[$pos] == "."); array_push($stack, $tmp); } else if(in_array($rpn[$pos], $allowed_operators)) { $second = array_pop($stack); $first = array_pop($stack); if($rpn[$pos] == '^') $result = eval("return pow($first, $second);"); else $result = eval("return ($first $rpn[$pos] $second);"); //echo "return ($first $rpn[$pos] $second);"; array_push($stack, $result); } $pos++; return r(); } r(); //echo $result;
Output for git.master, git.master_jit, rfc.property-hooks

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:
46.19 ms | 401 KiB | 8 Q