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){ Quote 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. Quote 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 Quote 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) ? Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.