ok Posted September 5, 2008 Share Posted September 5, 2008 Hi guys, very basic problem with foreach.. below is the codes. $multi_winner[$i] = $row['invited_by']; foreach ($multi_winner as $value2) { echo "<br>multipler_winner: ". $value2; } below is the error message. Warning: Invalid argument supplied for foreach() Thank you! Link to comment https://forums.phpfreaks.com/topic/122837-foreach-problem/ Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 Try this <?php $i=0; $multi_winner[$i] = 'test'; foreach ($multi_winner as $value2) { echo "<br>multipler_winner: ". $value2; } ?> Link to comment https://forums.phpfreaks.com/topic/122837-foreach-problem/#findComment-634371 Share on other sites More sharing options...
QuietWhistler Posted September 5, 2008 Share Posted September 5, 2008 What I do to catch errors with foreach loops, is checking if the variable is actually an array. So like this: <?php $multi_winner[ $i ] = $row[ "invited_by" ]; if( is_array( $multi_winner ) { foreach( $multi_winner as $value ) { print( "stuff" ); } } ?> Link to comment https://forums.phpfreaks.com/topic/122837-foreach-problem/#findComment-634592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.