Jump to content

Looping through multidimensional array with key


mo
 Share

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.