0

下面是我的每个循环。我想检查循环是否不为空,然后回显“此循环不为空”,否则回显“此列表为空”;这是什么语法?

foreach ($wholikes as $key => $list2){
echo "is in the list".$list2['userid'];
} 
4

3 回答 3

2

尝试这个:

if(empty($wholikes)){
    echo "This list is empty";
}else{
    foreach ($wholikes as $key => $list2){
        echo "is in the list".$list2['userid'];
    } 
}
于 2012-04-17T00:30:32.783 回答
0
if( !$wholikes) echo "Empty";

这就是它的全部内容。

于 2012-04-17T00:29:54.873 回答
0

在这种情况下,前两个答案将起作用,但在您想要的更一般的循环情况下:

$notEmpty = 0;
foreach ($wholikes as $key => $list2){
    $notEmpty = 1;
    echo "is in the list".$list2['userid'];
} 
if(notEmpty) {
   echo "Not empty.";
} else {
    echo "Empty";
}
于 2012-04-17T00:32:35.603 回答