Skip to content
Advertisement

PHP Laravel Check if Array is empty

I am struggling with displaying some content depending on if an array does have a value or not.Every time the code in the else part is executed. What’s wrong here? Is there any syntax error with this code? I’m using php laravel.

foreach($now as $v)
{
        $arry[$c++]=$v->Code; 
}
if($arry==null){
     Do Something
}
else{
     Do Something else
}

Advertisement

Answer

if ( sizeof($arry) ) { // If more than 0
   // Do Something
} else { // If 0
   // Do Something else
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement