Warning: Invalid argument supplied for foreach() in Php


Warning: Invalid argument supplied for foreach() in Php: This warning comes when you are not passing array to foreach. To fix this warning you can use is_array to check the argument type supplied to foreach. Here is an example – How to fix Warning: Invalid argument supplied for foreach().


Warning: Invalid argument supplied for foreach() in Php

Add the is_array() method to fix the warning –

Warning: Invalid argument supplied for foreach()

$array = array("John", "Rimmy", "Kelly");
//now add the following check 
if(is_array($array)){
foreach($array as $data){
echo $data;
}

}

The above check will fix your problem.


Advertisements

Add Comment

📖 Read More