dylandcor Posted July 9, 2009 Share Posted July 9, 2009 I have a staff page that has all the information contained in arrays. It also contains a short bio about each person answering questions, this data is in an array too. When I go to echo this data, it echos this in the actual page: $Smith['0']. This is what I actually wanted to echo, you can see below how this is generated. It assigns the correct name to the person, so that isn't the problem. Any help would be greatly appreciated! $last_names=array('Smith', 'Jones', 'Anderson'); $Smith=array('Answer 1', 'Answer 2', 'Answer 3'); foreach($lastname as $staffmember){ echo "Question 1: $$lastname[$i]['0'] <br> Question 2: $$lastname[$i]['1'] } Link to comment https://forums.phpfreaks.com/topic/165401-solved-arrays-in-foreach/ Share on other sites More sharing options...
J.Daniels Posted July 9, 2009 Share Posted July 9, 2009 The variables aren't consistent in your example, but here is a possible solution to what you are trying to do: $lastname = array('Smith', 'Jones', 'Anderson'); $Smith = array('Answer 1', 'Answer 2', 'Answer 3'); foreach($lastname as $staffmember) { $sm = $$staffmember; echo "Question 1: " . $sm['0'] . "<br> Question 2: " . $sm['1']; } Link to comment https://forums.phpfreaks.com/topic/165401-solved-arrays-in-foreach/#findComment-872337 Share on other sites More sharing options...
dylandcor Posted July 10, 2009 Author Share Posted July 10, 2009 I realize that now. Sorry. But it works perfectly! Thanks!!! Link to comment https://forums.phpfreaks.com/topic/165401-solved-arrays-in-foreach/#findComment-872451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.