andil01
andil01

Reputation: 375

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?

Upvotes: 0

Views: 45

Answers (2)

K.B
K.B

Reputation: 885

Try this

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

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

    }

Upvotes: 0

Mahipal Patel
Mahipal Patel

Reputation: 543

try like this

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

Upvotes: 2

Related Questions