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.3.0 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.10, 8.1rc1
0 1 2 3 {"0":true,"3":true} 0 1 3 {"0":true,"2":false,"3":true}

preferences:
54.82 ms | 459 KiB | 5 Q