3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test($reset = FALSE) { static $i; if ($reset) { unset($i); return; } if (!isset($i)) $i = 3; if ($i <= 0) return; return array('id' => $i--, 'someValue' => mt_rand()); } $rappels = array(); $i = 0; while($row = test()) { foreach($row as $key=>$val) { $rappels[$i][$key] = $val; } $i++; } var_dump($rappels); test(TRUE); $rappels = array(); while($row = test()) { $rappels[] = $val; } var_dump($rappels);

preferences:
32.4 ms | 402 KiB | 5 Q