I've a multidimensionnal array like that, and I wan't to check if all of the "open_at" and "closed_at" values are NULL.
array:7 [▼
0 => array:2 [▼
0 => array:2 [▼
"open_at" => null
"closed_at" => "11:03"
]
1 => array:2 [▼
"open_at" => "13:00"
"closed_at" => "16:00"
]
]
1 => array:2 [▼
0 => array:2 [▼
"open_at" => "09:00"
"closed_at" => "12:00"
]
1 => array:2 [▼
"open_at" => "12:30"
"closed_at" => "17:00"
]
]
2 => array:2 [▼
0 => array:2 [▼
"open_at" => "08:00"
"closed_at" => "18:00"
]
1 => array:2 [▼
"open_at" => null
"closed_at" => null
]
]
3 => array:2 [▼
0 => array:2 [▼
"open_at" => null
"closed_at" => null
]
1 => array:2 [▼
"open_at" => null
"closed_at" => null
]
]
...
I've tried with multiple for and foreach loop like, with no success...
for ( $i = 0; $i <6 ; $i++) {
for ($j = 0; $j < 2; $j++) {
if(empty($hours[$i][$j]["open_at"])){
$null="complete";
}
else{
$null="empty";
}
return $null;
}
}
The array should be checked as empty only if all the "open_at" and "closed_at" values are set to NULL. As saw in the example above, the first values can be set to NULL, but the array should not be checked as empty in that case.
The goal is to don't execute the code bellow only if all the "open_at" and "closed_at" are set to NULL.
$hours = $request->get('hours');
//check if empty here
foreach ($hours as $key => $period) {
foreach($period as $attribute => $value){
$shops_hour = new Shops_hour();
$shops_hour->shop_id=$shop->id;
$shops_hour->day=$key;
$shops_hour->period=$attribute;
$shops_hour->open_at=$hours[$key][$attribute]["open_at"];
$shops_hour->closed_at=$hours[$key][$attribute]["closed_at"];
$shops_hour->save();
}
}
Thank you in advance,