How would I create an array in PHP that has $x empty elements? The $x is unknown and varying value. For example, if I wanted to create an array of 3 elements, I could just do:
$array = array(null,null,null);
However, I don’t know what $x is and there could be million elements, I need to do this automatically.
As usual with PHP there’s a function for this:
array_fill()– Fill an array with valuesExample:
This will create an array filled with the $x elements valued ‘value’ starting at array offset 0.