digiman999 Posted May 27, 2013 Share Posted May 27, 2013 Hi peeps, I have this code here in a function.php file. $row = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM releases"));$GLOBALS ['releaseids']=$row['id']; global $releaseids; I then try & use this within a function function postcontainer(){global $releaseids; foreach ($releaseids as $releaseid){ echo "this is the id";} }} Every time however, I keep getting Invalid argument supplied for foreach() in... This still applies too if it isn't put inside or outside of a function. Very grateful digiman Link to comment https://forums.phpfreaks.com/topic/278438-foreach-using-globals-variable/ Share on other sites More sharing options...
Jessica Posted May 27, 2013 Share Posted May 27, 2013 Okay, don't even bother trying to do it that way. Pass the values to the function. Plus, a function shouldn't really echo anything, it should just return the data. You don't need a function to do what you're trying to do, just the foreach() wherever your values are already defined. Stop using global completely. Forget that word exists. Link to comment https://forums.phpfreaks.com/topic/278438-foreach-using-globals-variable/#findComment-1432540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.