0

I have a multidimensional array within these arrays contains array objects. How can I iterate over a specific array object for example in value2 > [1] > iterate all Account_ID's in members array?

Array( 
    [value1] => text
    [value2] => Array ( 
        [0] => stdClass Object (
            [Project_Title] => Project B Test
            [members] => Array(
                [0] => stdClass Object ( [Account_ID] => 5 )
            ) 
        ) 
        [1] => stdClass Object (
            [Project_Title] => Project A Test
            [members] => Array( 
                [0] => stdClass Object ([Account_ID] => 9 ) 
                [1] => stdClass Object ([Account_ID] => 11) 
                [2] => stdClass Object ([Account_ID] => 13) 
                [3] => stdClass Object ([Account_ID] => 14) 
                [4] => stdClass Object ([Account_ID] => 15) 
                [5] => stdClass Object ([Account_ID] => 16) 
                [6] => stdClass Object ([Account_ID] => 17) 
                [7] => stdClass Object ([Account_ID] => 18) 
                [8] => stdClass Object ([Account_ID] => 19)
            )
        ) 
    )
)
1
  • 3
    Have you tried any recursive function programming ? What code have you experimented on so far? Commented Nov 20, 2011 at 22:42

2 Answers 2

1

Basically you can do this by doing exactly what you are saying. Something like this will work!

foreach( $array['value2'][1]->members as $key => $memberObject ) {
    echo $memberObject->Account_ID ."<br />";
}
Sign up to request clarification or add additional context in comments.

Comments

0

This could be one basic solution:

foreach ($array['value2'] as $object) {
    foreach ($object->members as $obj) { 
        echo $obj->Account_ID;
    }        
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.