我有以下代码,但我不确定为什么我的数组仍然是空的,因为我的想法是如果 foreach 是空的,它应该加载带有“No Open Homes”的 else 语句:
$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;
}
}