stijn0713 Posted July 18, 2012 Share Posted July 18, 2012 What is invalid in this expression? It seems, it does the job tho foreach ($_POST as $key => $value){ foreach($value as $k => $v){ also this seems to be invalid foreach ($_SESSION as $value){ foreach($value as $k => $v){ Link to comment https://forums.phpfreaks.com/topic/265893-nvalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
trq Posted July 18, 2012 Share Posted July 18, 2012 In both examples, $value is quite obviously not an array if that is the error you are receiving. Link to comment https://forums.phpfreaks.com/topic/265893-nvalid-argument-supplied-for-foreach/#findComment-1362392 Share on other sites More sharing options...
lfernando Posted July 18, 2012 Share Posted July 18, 2012 Either $_POST, $value or $_SESSION are not arrays, so the "foreach" expression is invalid. Try using if(is_array($value)) { foreach($value.. } Its always a good idea to check if the variable is an array before performing a foreach Link to comment https://forums.phpfreaks.com/topic/265893-nvalid-argument-supplied-for-foreach/#findComment-1362413 Share on other sites More sharing options...
stijn0713 Posted July 18, 2012 Author Share Posted July 18, 2012 my post and sessions arrays are two dimentional. I thought that was the way of iterating throught a 2dim array? Maybe because, the SESSION and POST is not always 2 layers deep, i should indeed do if(is_array($value) ? Link to comment https://forums.phpfreaks.com/topic/265893-nvalid-argument-supplied-for-foreach/#findComment-1362423 Share on other sites More sharing options...
stijn0713 Posted July 18, 2012 Author Share Posted July 18, 2012 Solved, thanks for the tip! Link to comment https://forums.phpfreaks.com/topic/265893-nvalid-argument-supplied-for-foreach/#findComment-1362426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.