MattR Posted June 26, 2009 Share Posted June 26, 2009 This is the code I have: function EpisodeList() { $episodesexploded = explode('||', $episodes); foreach ($episodesexploded as $episode) { echo $episode . "<br />"; } } $episodes is an array from a query. The error I get is: Notice: Undefined variable: episodes in /file.php on line 85 Can't figure out why ??? Link to comment https://forums.phpfreaks.com/topic/163780-solved-cant-get-foreach-to-work/ Share on other sites More sharing options...
gevans Posted June 26, 2009 Share Posted June 26, 2009 You need to pass the array to your function; <?php $episodes = array("once", "twice", "thrice"); function EpisodeList($episodes) { $episodesexploded = explode('||', $episodes); foreach ($episodesexploded as $episode) { echo $episode . "<br />"; } } EpisodeList($episodes); Link to comment https://forums.phpfreaks.com/topic/163780-solved-cant-get-foreach-to-work/#findComment-864157 Share on other sites More sharing options...
MattR Posted June 26, 2009 Author Share Posted June 26, 2009 Ha, something so simple, got it working, thank you Link to comment https://forums.phpfreaks.com/topic/163780-solved-cant-get-foreach-to-work/#findComment-864158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.