3v4l.org

run code in 300+ PHP versions simultaneously
<?php $expression = "5+4^3^2^1"; if (!preg_match('~^-?\d*\.?\d+([*/+-^]-?\d*\.?\d+)*$~', $expression)) { echo "invalid expression"; } else { $components = preg_split('~(?<=\d)([*/+-^])~', $expression, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); var_export($components); // ['5','+','4','^','3','^','2','^','1'] while (($index = array_search('^', $components)) !== false) { array_splice($components, $index - 1, 3, pow($components[$index - 1], $components[$index + 1])); var_export($components); // ['5', '+', 64, '^', '2', '^', '1'] // ['5', '+' ,4096, '^', '1'] // ['5', '+', 4096] } while (($index = array_search('*', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] * $components[$index + 1]); var_export($components); } while (($index = array_search('/', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] / $components[$index + 1]); } while (($index = array_search('+', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] + $components[$index + 1]); // [4101] } while (($index = array_search('-', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] - $components[$index + 1]); } echo $components[0]; // 4101 }
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => '5', 1 => '+', 2 => '4', 3 => '^', 4 => '3', 5 => '^', 6 => '2', 7 => '^', 8 => '1', )array ( 0 => '5', 1 => '+', 2 => 64, 3 => '^', 4 => '2', 5 => '^', 6 => '1', )array ( 0 => '5', 1 => '+', 2 => 4096, 3 => '^', 4 => '1', )array ( 0 => '5', 1 => '+', 2 => 4096, )4101

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:
33.62 ms | 402 KiB | 8 Q