3v4l.org

run code in 300+ PHP versions simultaneously
<?php $expression = "-11+3*1*4/-6-12"; 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); // ['-11','+','3','*','1','*','4','/','-6','-','12'] while (($index = array_search('*',$components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] * $components[$index + 1]); var_export($components); // ['-11','+','3','*','4','/','-6','-','12'] // ['-11','+','12','/','-6','-','12'] } while (($index = array_search('/', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] / $components[$index + 1]); var_export($components); // [-'11','+','-2','-','12'] } while (($index = array_search('+', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] + $components[$index + 1]); var_export($components); // ['-13','-','12'] } while (($index = array_search('-', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] - $components[$index + 1]); var_export($components); // [-25] } echo current($components); // -25 }
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => '-11', 1 => '+', 2 => '3', 3 => '*', 4 => '1', 5 => '*', 6 => '4', 7 => '/', 8 => '-6', 9 => '-', 10 => '12', )array ( 0 => '-11', 1 => '+', 2 => 3, 3 => '*', 4 => '4', 5 => '/', 6 => '-6', 7 => '-', 8 => '12', )array ( 0 => '-11', 1 => '+', 2 => 12, 3 => '/', 4 => '-6', 5 => '-', 6 => '12', )array ( 0 => '-11', 1 => '+', 2 => -2, 3 => '-', 4 => '12', )array ( 0 => -13, 1 => '-', 2 => '12', )array ( 0 => -25, )-25

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