简体   繁体   中英

How to extract an array in PHP from foreach loop?

I want to extract item 6 and item 9 from an array, I can get ingle values out using the [0] singled indexed row

But looking for the vector this does not work

$vector1 =  ($result['item3']['item6'][‘item9’]);

What is the best way to extract the arrays for item 6 and item 9 ?

Array
([0] => Array
    ([item1] => 123
     [item2] => 345
     [item3] => Array
        ([0] => Array
            ([item4] => Array
                ([item6] => 567
                 [item7] => 678
                 [item8] => Array
                    ([0] => Array
                        ([item9] => abc)
                    )
                )
            )
        )
    )
)
$item6 =  $result[0]['item3'][0]['item4']['item6'];

$item9 =  $result[0]['item3'][0]['item4']['item8'][0]['item9'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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