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 ) ) ) Quote Link to comment 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? Quote Link to comment 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; } Quote Link to comment 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; } } Quote Link to comment Share on other sites More sharing options...
mo Posted September 6, 2010 Author Share Posted September 6, 2010 still not working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.