3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(true, false, false, true); $ao = new ArrayObject($a); foreach ($a as $key => $value) { echo $key, "\n"; if (!$value) { unset($a[$key]); } } echo json_encode($a), "\n"; echo "\n"; foreach ($ao as $key => $value) { echo $key, "\n"; if (!$value) { unset($ao[$key]); } } echo json_encode($ao), "\n";
Output for 7.0.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
0 1 2 3 {"0":true,"3":true} 0 1 3 {"0":true,"2":false,"3":true}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 0 1 2 3 {"0":true,"3":true} 0 1 3 {"0":true,"2":false,"3":true}
Output for 5.6.17
0 1 2 3 {"0":true,"3":true} 0 1 Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in /in/sM8A5 on line 16 0 2 Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in /in/sM8A5 on line 16 0 3 {"0":true,"3":true}
Output for 4.3.5
Fatal error: Cannot instantiate non-existent class: arrayobject in /in/sM8A5 on line 4
Process exited with code 255.

preferences:
144.38 ms | 401 KiB | 159 Q