3v4l.org

run code in 500+ PHP versions simultaneously
<?php gc_enable(); $arr = []; getMemory(); for ($i = 0; $i < 5000; $i++) { $d = str_repeat("Hello, world!", 400); $arr[$i][] = $d; } // Clear the sub-arrays foreach (array_keys($arr) as $index) { unset($arr[$index]); } // Clear the sub-arrays foreach ($arr as &$subArray) { unset($subArray); } array_splice($arr, 0); // Remove all elements from the main array unset($arr); gc_collect_cycles(); getMemory(); function getMemory() { echo date("Y-m-d H:i:s") . ' :: ' . round( (memory_get_usage(true) / 1000000), 2 ) . PHP_EOL; }

preferences:
22.31 ms | 483 KiB | 4 Q