3v4l.org

run code in 300+ PHP versions simultaneously
<?php $equation = '1-1'; $stored = $equation; $components = preg_split('~([*/%+-])~', $stored, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 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]); } while (($index = array_search('%', $components)) !== false) { array_splice($components, $index - 1, 3, fmod($components[$index - 1], $components[$index + 1])); } while (($index = array_search('+', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] + $components[$index + 1]); } $count = 0; var_dump($components); while (($index = array_search('-', $components)) !== false) { echo "First\n"; var_dump($components); array_splice($components, $index - 1, 3, $components[$index - 1] - $components[$index + 1]); echo "Second\n"; var_dump($components); $count++; if($count > 3) die('Too many'); } echo current($components);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
Deprecated: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated in /in/IhW94 on line 6 array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } First array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } Second array(1) { [0]=> int(0) } 0
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.0.0 - 8.0.30
array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } First array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } Second array(1) { [0]=> int(0) } 0
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } First array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Notice: Undefined offset: -1 in /in/IhW94 on line 25 Notice: Undefined offset: 1 in /in/IhW94 on line 25 Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Notice: Undefined offset: -1 in /in/IhW94 on line 25 Notice: Undefined offset: 1 in /in/IhW94 on line 25 Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Notice: Undefined offset: -1 in /in/IhW94 on line 25 Notice: Undefined offset: 1 in /in/IhW94 on line 25 Second array(1) { [0]=> int(0) } Too many
Output for 7.3.32, 7.4.26
array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } First array(3) { [0]=> string(1) "1" [1]=> string(1) "-" [2]=> string(1) "1" } Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Second array(1) { [0]=> int(0) } First array(1) { [0]=> int(0) } Second array(1) { [0]=> int(0) } Too many

preferences:
231.04 ms | 413 KiB | 5 Q