daveoliveruk Posted February 5, 2008 Share Posted February 5, 2008 I have the following piece of code: foreach($classRequests as $key => $val) { if(is_array($val)){ foreach ($val as $key2 => $val2) { if ($key2 == "UserID") $strIDs2 = add2string($strIDs2, $val2, ','); if ($key2 == "RequestedUserID") $strIDs2 = add2string($strIDs2, $val2, ','); } } else { if ($key == "UserID") $strIDs2 = add2string($strIDs2, $val, ','); if ($key == "RequestedUserID") $strIDs2 = add2string($strIDs2, $val, ','); } } And in the logs I'm getting: [Tue Feb 5 11:57:36 2008] [error] PHP Warning: Invalid argument supplied for foreach() in /home/public_html/menu_home.php on line 589 Is tehre anyway to avoid this? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/ Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 What is $classRequests ? Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458866 Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 If its the result of a mysql query, you need to extract the arrays from it (mysql_fetch_array() or mysql_fetch_assoc()) before you can use it in the foreach loop. Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458871 Share on other sites More sharing options...
daveoliveruk Posted February 5, 2008 Author Share Posted February 5, 2008 $classRequests is an array returned from an API Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458922 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 print_r($classRequests); And post what it contains. Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458927 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 And I assume foreach($classRequests as $key => $val) { is line 589? Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458938 Share on other sites More sharing options...
daveoliveruk Posted February 5, 2008 Author Share Posted February 5, 2008 No its if(is_array($val)). When I check for an array. Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458942 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 can't be....it's gotta be foreach($classRequests as $key => $val) { or foreach ($val as $key2 => $val2) { Link to comment https://forums.phpfreaks.com/topic/89571-invalid-argument/#findComment-458945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.