3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $bar; public function __construct() { $this->bar = rand(0, 1); } public function getBar() { return $this->bar; } } $quux = array(); for ($i=0; $i<10; $i++){ $quux[] = new Foo(); } foreach ($quux as $k => $q) { if (!$q->getBar()) { unset($quux[$k]); } } print_r($quux); $qwax = array(); foreach ($quux as $q) { if ( $q->getBar()) { $qwax[] = $q; } } print_r($qwax);

preferences:
32.02 ms | 402 KiB | 5 Q