php - create,dynamically, an array initialized with N null elements
Actually a call to array_fill
should be sufficient:
//...
public function create_array($num_elements){
return array_fill(0, $num_elements, null);
}
//..
var_dump(create_array(3));
/*
array(3) {
[0]=> NULL
[1]=> NULL
[2]=> NULL
}
*/
for ($i = 0; $i < $num_elements; $i++) {
$array[$i] = null;
}