"Ivan S" <iv*********@gmail.comwrote in message
news:f0**********************************@i76g2000 hsf.googlegroups.com...
On 10 srp, 05:25, Olaf Schinkel <tr...@schinkel.tvwrote:
Ivan S schrieb:
I'm using next snippet:
$somearray = array(...);
foreach($somearray as $item1) {
foreach($item1 as $item2) {
// ... do something ...
}
}
...and I'm getting next error:
Invalid argument supplied for foreach()
on second foreach.
This works on PHP 5, but on PHP 4 I get that error (in Apache logs),
but site seems to work ok.
Is there any way to avoid that error?
Tnx.
The function is_array() exists :-)
I know that...I wasn't aware that my input array could contain
unexpected values (such as non array values).
=========
strictly speaking, avoid the error like this:
$somearray = array(...);
foreach ($somearray as $item1)
{
if (!is_array($item1)){ $item1 = array($item1); }
foreach ($item1 as $item2)
{
// do something...
}
}
that way, if $item1 is not an array but still a usable, otherwise valid,
value then your next foreach will be able to process it normally...based on
whatever '...do something...' is.