3v4l.org

run code in 200+ php & hhvm versions
<?php error_reporting(-1); $input = '243+6743-78*2='; $inputLenght = mb_strlen($input); $number = 0; $result = 0; $op = ''; for ($i = 0; $i < $inputLenght; $i++){ $char = mb_substr($input, $i, 1); if ($char == '+' || $char == '-' || $char == '*' || $char == '='){ if ($op == ''){ reporting($op, $result, $number, $char); $result = $number; }else if ($op == '+'){ reporting($op, $result, $number, $char); $result = $result + $number; }else if ($op == '-'){ reporting($op, $result, $number, $char); $result = $result - $number; }else if ($op == '*'){ reporting($op, $result, $number, $char); $result = $result * $number; } $op = $char; $number = 0; } elseif (is_numeric($char)){ $number = $number * 10 + $char; } else { echo "Неверный символ: {$char}\n"; } } echo "Ответ: {$input}{$result}\n"; function reporting($op, $result, $number, $char){ echo "op = [{$op}], result = [{$result}], number = [{$number}], char = [{$char}]\n"; }
based on uNt3X
Output for 4.3.0 - 5.6.38, hhvm-3.10.1 - 3.17.3, 7.0.0 - 7.3.0
op = [], result = [0], number = [243], char = [+] op = [+], result = [243], number = [6743], char = [-] op = [-], result = [6986], number = [78], char = [*] op = [*], result = [6908], number = [2], char = [=] Ответ: 243+6743-78*2=13816