I have this multidimensional array in PHP:
Array
(
[47] => Array
(
[2019-02-24] => Array
(
[AVA_Id] => 1
[AVA_Status] => Open
)
[2019-02-25] => Array
(
[AVA_Id] => 3
[AVA_Status] => Open
)
[2019-02-28] => Array
(
[AVA_Id] => 4
[AVA_Status] => Close
)
)
[48] => Array
(
[2019-02-26] => Array
(
[AVA_Id] => 2
[AVA_Status] => Open
)
)
)
How for a known date range I can fill this array with missing dates ?
My date range is the following:
Array ( [0] => 2019-02-24 [1] => 2019-02-25 [2] => 2019-02-26 [3] => 2019-02-27 [4] => 2019-02-28 [5] => 2019-03-01 [6] => 2019-03-02 )
For example, for array wit the key 47, I would need to add missing date: 2019-02-26, 2019-02-27, 2019-03-01 and 2019-03-02 because these dates are into the range of dates but not into the array under the key 47. Same thing for the key 48.
My try was this one:
foreach($daterange as $date){
$date = $date->format('Y-m-d');
if(in_array($myarray[$date]))
$newarray[$date] = $myarray[$date];
else
$newarray[$date] = 0;
}
AVA_IdandAVA_Status) do you want to add for the missing dates, or do you just want an empty array?AVA_Idcould be0andAVA_Statuscould beno. Thanks for your help.in_arrayuseisset.