具体代码如下:<?php
$proImgs = getAllImgByProId($row['id']);
//在这个位置希望加入 if ($proImgs != null) 判断proImgs是否为空,不为空才进行foreach
foreach ($proImgs as $img):
?>
<p>html</p>
<?php endforeach;?>
但在注释位置添加 if无法像普通if else进行判断,会提示error,我该如何进行加入判断
$proImgs = getAllImgByProId($row['id']);
//在这个位置希望加入 if ($proImgs != null) 判断proImgs是否为空,不为空才进行foreach
foreach ($proImgs as $img):
?>
<p>html</p>
<?php endforeach;?>
但在注释位置添加 if无法像普通if else进行判断,会提示error,我该如何进行加入判断
foreach ($proImgs as $img):
?>
<p>html</p>
<?php
endforeach;
endif;
?>
其实并不需要判断 proImgs 是否为空,为空是不会进入 foreach 循环体的
if ($proImgs != null) {
foreach ($proImgs as $img){
?>
<p>html</p>
<?php
}
}
?>或者<?php
if ($proImgs != null) {
foreach ($proImgs as $img){
echo '<p>html</p>';
}
}
?>
还是
$proImgs != NULL