简体   繁体   English

如何遍历包含数组对象的多维数组?

[英]How can I iterate over a multidimensional array containing array objects?

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? 我如何遍历特定的数组对象,例如在value2> [1]>遍历成员数组中的所有Account_ID?

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)
            )
        ) 
    )
)

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

This could be one basic solution: 这可能是一个基本解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM