As far as I know, there is no built-in php function for this, you need to do it through a loop or using a custom method that recursively calls something like array_fill, distorted in @Amber's answer;
I assume that you want to create an empty array with arrays of arrays. For example, you want to get the final results, as shown below, from an array of 3 arrays:
$final_array = array(array(), array(), array());
This is simple for simple code, but for an array of arbitrary size, such as an array of 3 arrays of 3 arrays, it starts to get complicated initialization before use:
$final_array = array(array(array(), array(), array()), array(array(), array(), array()), array(array(), array(), array()));
... etc...
I get disappointed. It would be nice to have a simple way to declare an initialized array of arrays of any depth so that you can use it without checking or throwing errors.
Ray Oct 13 '14 at 20:34 2014-10-13 20:34
source share