vendredi 27 novembre 2015

error of foreach with empty array

I'm working in Laravel 5 using Blade as motor of templates. I'm passing an array from the controller to the view, and I noticed that when I loop on it using the foreach clausule and the array is empty it gives error, exactly this:

Invalid argument supplied for foreach() 

I had the same error in the controller and I fix it temporaly making:

if(count($student)!=0)

I said temporaly because I don't think it this the best way to do it. But know, in the view I have the same error. So, it's normal? how could I fix it in a better way? why when the array is empty the foreach clausule gives that error?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire