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?
array_fillthe best solution for you?array_fillis a core function - nothing will be faster than that. What would you expect from the "best solution"?array_fillis the function which works faster and easiest, probably it's the best solution (personal opinion).