简体   繁体   English

循环从php数组获取值

[英]loop to get values from php array

I have array which contents are; 我有哪些内容的数组;

[@attributes] => Array
    (
        [type] => 1
    )
[shops] => Array
    (
        [basead] => Array
            (
                [shop] => Array
                    (
                        [0] => Array
                            (
                                [id] => KN0100060500211230
                                [entryname] => 陽陽ラーメン本店東栄店
                                [searchnum] => 7187766
                            )

                        [1] => Array
                            (
                                [id] => KN0114102400000170
                                [entryname] => 炭火焼肉たんたん
                                [searchnum] => 7187766
                            )
                    )

            )

    )

I have this code to get the values I wanted; 我有这段代码来获取所需的值;

foreach ( $hascompany as $company ) {
            $companyId = $company['shops']['basead']['shop']['id'];
            $entryName = $company['shop']['basead']['shop']['entryname'];
            $priority = $company['shop']['basead']['shop']['priority'];
            $searchNum = $company['shop']['basead']['shop']['searchNum'];
}

How can I do loop to get the values I want from the array List? 我该如何循环以从数组List中获取所需的值?

try like this 这样尝试

foreach ( $hascompany['shops']['basead']['shop'] as $company ) {
            $companyId = $company['id'];
            $entryName = $company['entryname'];
            $searchNum = $company['searchNum'];
}

Try this 尝试这个

    foreach ( $hascompany['shops']['basead']['shop'] as $shop ) {

         $companyId = $shop['id'];
         $entryName = $shop['entryname'];
         $priority = $shop['priority'];
         $searchNum = $shop['searchNum'];

    }

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

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