I have the following code but I am unsure why my array is still empty as my thinking is if the foreach is empty it should load the else statement with the ‘No Open Homes’:
$openHomeTimes = array();
if(!empty($detail) && in_array('OpenHomes', $detail))
{
foreach ($detail['OpenHomes'] as $openHome)
{
$startO = $openHome['Start'];
$finishO = $openHome['End'];
$startConvert = preg_replace('~\D~', '', $startO);
$start = date('D j M g a',$startConvert / 1000);
$finishConvert = preg_replace('~\D~', '', $finishO);
$finish = date('g:ia',$finishConvert / 1000);
$openHomeDetail = $start." - ". $finish;
$openHomeTimes[] = $openHomeDetail;
}
}else{
if(!empty($openHomeTimes))
{
$message = 'No Open Homes';
$openHomeTimes = $message;
}
}
If I don’t completely misunderstand you, simple logic fixes might be sufficient.
That foreach is not a condition for the outer if/else construct.