You Are Here Home > How to fix: Warning: Invalid argument supplied for foreach()
DirectorySync is a directory synchronizing and backup utility providing automated, real-time syncing and scheduled, configurable backups at an affordable price.

How to fix: Warning: Invalid argument supplied for foreach()

This warning happens only if you try to use foreach on a non array like:

$myvar = 10;
foreach ($myvar as $value) {}

If you run this, you will get:

Warning: Invalid argument supplied for foreach() in YOUR_FILE on line FOREACH_LINE

To fix this just cast $myvar to array like this:

$myvar = 10;
foreach ((array) $myvar as $value) {}
How to fix: Warning: Invalid argument supplied for foreach()
Filed under: PHP,Web Development   Posted by: Codehead
Do you have any questions? ask here.




2 Comments »

  1. soyeb ahmedq:
     

    thanks very much i got great help from it.

    Comment

  2.  

    Thank you for this, sorted my problem, i thought i would give a minute of my time to say thank you as not everyone will, thanks for your time! :)

    Comment

RSS feed for comments on this post. TrackBack URL

Leave a comment