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; } public function nullify() { unset($this->bar); } } $quux = array(); for ($i=0; $i<10; $i++){ $quux[] = new Foo(); } foreach ($quux as $q) { if ($q->getBar()) { unset($q); } } echo '<pre>'; print_r($quux); echo '</pre>'; $qwax = array(); foreach ($quux as $q) { if ($q->getBar()) { $qwax[] = $q; } } echo '<pre>'; print_r($qwax); echo '</pre>';

preferences:
35.24 ms | 404 KiB | 5 Q