php - create,dynamically, an array initialized with N null elements

Viewed 23047

I want to create dynamically an array with N (without knowking N) elements.

Something like a function

public function create_array($num_elements){

     .....
}

that return me something like

//call the function.... 
create_array(3);

//and the output is: 
array{
   0 => null
   1 => null
   2 => null
}

I've already thought about array_fill and a simple foreach loop.

Are there any other solutions?

6 Answers
Related