I have an array with these entries:
$row['10']['something'] = "21";
$row['5']['something'] = "42";
I want to make a string from index 0 to 10. But only index "5" and "10" are set. However I want a string like this:
0, 0, 0, 0, 42, 0, 0, 0, 0, 21
Currently I am using this:
for($i=0; $i <= 10; $i++) {
if (!array_key_exists($i, $row))
$row[$i]['something'] = 0;
if ($i == 10)
$string .= $row['10']['something'];
else
$string .= $row[$i]['something'].', ';
}
But I need it more efficient. I could do array_map and implode but I don't know how to add the 0, 0, 0,...
I would only get 21, 42
To clarify:
I can't overwrite single indexes the array called $row
in this example is filled from a sql query. It will completely overwrite an existing array.