score:1

Accepted answer

To answer your question how to create an array that holds zero values and merge with the data array (I assume).

You can use array_fill to create the array with zeros, and use array_replace to replace with the data array.

$arr = array_fill(0, 10, 0); //[0,0,0,0,0,0,0,0,0,0]

$data = [2 => 15, 5 =>10, 7 => 16]; // your data

$new = array_replace($arr, $data);
var_dump($new); // [0,0,15,0,0,10,0,16,0,0]

Related Query

More Query from same tag