3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_objects() { $array = array(); for ($i=0; $i<5000; $i++) { $object = new stdClass(); $object->a = rand(); $object->b = rand(); $object->c = rand(); $object->d = rand(); $object->e = rand(); $array[] = $object; } return $array; } $results = array(); for ($i=0; $i<30; $i++) { $results = get_objects(); echo memory_get_usage(true) . "\n"; // assigning empty array fixes the problem // $results = array(); }

preferences:
22.61 ms | 405 KiB | 5 Q