下面是我的每个循环。我想检查循环是否不为空,然后回显“此循环不为空”,否则回显“此列表为空”;这是什么语法?
foreach ($wholikes as $key => $list2){
echo "is in the list".$list2['userid'];
}
尝试这个:
if(empty($wholikes)){
echo "This list is empty";
}else{
foreach ($wholikes as $key => $list2){
echo "is in the list".$list2['userid'];
}
}
if( !$wholikes) echo "Empty";
这就是它的全部内容。
在这种情况下,前两个答案将起作用,但在您想要的更一般的循环情况下:
$notEmpty = 0;
foreach ($wholikes as $key => $list2){
$notEmpty = 1;
echo "is in the list".$list2['userid'];
}
if(notEmpty) {
echo "Not empty.";
} else {
echo "Empty";
}