Do array_fill and foreach not work?
Of course, the simplest solution that comes to mind is
function create_array($num_elements) { $r = array(); for ($i = 0; $i < $num_elements; $i++) $r[] = null; return $r; }
array_fill should also work:
function create_array($num_elements) { return array_fill(0, $num_elements, null); }
source share