Jump to content

Looping through multidimensional array with key


mo

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
                )

        )
)

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;
		}
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.