The array below should have a child array for every "point" value from 1 - 7, but 2, 4 and 6 are missing. How can I insert an array for each of those missing values, with a "value" of NULL?
I tried a for($i = 1; $i <= 7; $i++) and inside foreach'ing over my array to see if 'point' == $i or not but that doesn't work.
This is already in a nested foreach of a fairly large array so performance is somewhat important.
Code so far (incomplete and obviously not working)
foreach($measurements as $measurement_id => $set)
{
for($i = 1; $i <= 7; $i++)
{
foreach($set as $key => $value)
{
$fill = array('value' => null);
if($value['point'] == $i)
$output[$measurement_id][$key] = $value;
else
$output[$measurement_id][$key] = $fill;
}
}
}
The array:
[0] => Array
(
[point] => 1
[value] => 1.0
)
[1] => Array
(
[point] => 3
[value] => 2.0
)
[2] => Array
(
[point] => 5
[value] => 3.0
)
[3] => Array
(
[point] => 7
[value] => 4.0
)
The result should be
[0] => Array
(
[point] => 1
[value] => 1.0
)
[1] => Array
(
[point] => 2
[value] => NULL
)
[2] => Array
(
[point] => 3
[value] => 2.0
)
[3] => Array
(
[point] => 4
[value] => NULL
)
[4] => Array
(
[point] => 5
[value] => 3.0
)
[5] => Array
(
[point] => 6
[value] => NULL
)
[6] => Array
(
[point] => 7
[value] => 4.0