In this article, it mentions:
foreach does not support the ability to suppress error messages using '@'.
How do I avoid an output foreach
error? I do not want see:
Warning: Invalid argument supplied for foreach()
Is there a way to make an if else
judgement?
Before foreach check if variable contain array:
if (is_array($var))
{
foreach...
}
prefix the variable with a (array) like this.
foreach( (array) $array_thats_not_an_array as $key => $value ){
echo $key . ' ' . $value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With