mo Posted September 6, 2010 Share Posted September 6, 2010 I have a array as follows and I want to look by key where the key is 'ABCD', 'EFGH', etc.. I am using foreach but it is not working. How can I accomplish this? Array ( [0] => Array ( [ABCD] => Array ( [venue_id] => 1003 [has_dining] => X [table_count] => 0 [serves_alcohol] => X ) ) [1] => Array ( [EFGH] => Array ( [venue_id] => 1003 [has_dining] => X [table_count] => 0 [serves_alcohol] => X ) ) ) Link to comment https://forums.phpfreaks.com/topic/212634-looping-through-multidimensional-array-with-key/ Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2010 Share Posted September 6, 2010 Can you explain better what it is you are trying to do? Link to comment https://forums.phpfreaks.com/topic/212634-looping-through-multidimensional-array-with-key/#findComment-1107725 Share on other sites More sharing options...
objnoob Posted September 6, 2010 Share Posted September 6, 2010 foreach ($myArray as $position => $element){ echo $element[0].' is at '.$position; } Link to comment https://forums.phpfreaks.com/topic/212634-looping-through-multidimensional-array-with-key/#findComment-1107726 Share on other sites More sharing options...
mo Posted September 6, 2010 Author Share Posted September 6, 2010 I do not have the position, I want to read the array with a key value. I am looping through a main array and printing values. I have a multidimensional array which has additional values that I need to read based on the current key of my main loop. Here is my current code for the loop, which is not working. $venue_key equals the key value of my main loop. foreach($attributes as $attribute) { foreach($attribute[$venue_key] as $key => $value) { echo $key.'->'.$value; } } Link to comment https://forums.phpfreaks.com/topic/212634-looping-through-multidimensional-array-with-key/#findComment-1107727 Share on other sites More sharing options...
mo Posted September 6, 2010 Author Share Posted September 6, 2010 still not working. Link to comment https://forums.phpfreaks.com/topic/212634-looping-through-multidimensional-array-with-key/#findComment-1107861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.