简体   繁体   English

使用PHP代码从多维数组中获取数据

[英]get data from multi-dimensional array using PHP code

I'm trying to get this data [label] => For Rent from a multi-dimensional array. 我正试图从多维数组中获取此数据[label] => For Rent Here is my array 这是我的阵列

Array ( [listing_id] => 0 
        [fields] => 
                   Array ( [1] => Property House 7 [2] => 30 [4] => sdfasd
                           [11] => Bungalow [10] => Philippines [12] => 1800100
                           [13] => 1 [14] => 1 [15] => Yes [16] => Yes [17] => Yes
                           [18] => Yes [26] => Yes [25] => Yes [24] => Yes
                           [23] => Yes [22] => Yes [21] => Yes [20] => Yes [19] => Yes) 
        [fees] => Array ( 
            [30] => stdClass Object ( [id] => 2 [label] => For Rent [amount] => 0.00
                                      [days] => 7 [images] => 0
                                      [categories] => 
                                        Array ( [all] => 0 
                                [categories] => Array ( [0] => 30 ) ) [extra_data] => ) ) 

                                [images] => Array ( ) [thumbnail_id] => 0 )

How will I echo the label that has a value of For Rent using PHP code 如何使用PHP代码回显具有For Rent值的label

Try 尝试

$array[fees][30]->label

Where $array is whatever you're top level variable is. $array是你顶级变量的地方。

echo $yourArray['fees'][30]->label

It's not just an array... it's an array with an object in it. 它不仅仅是一个数组......它是一个包含对象的数组。 Use the -> to access object properties. 使用->访问对象属性。

You can access any value of array by their keys. 您可以通过键访问任何数组值。 simply access For Rent like this :- 只需访问For Rent像这样: -

echo $arrayName['fees'][30]->label

This will display For Rent like ( An Arrow operator because to access an object attribute you have to use this ) 这将显示For Rent like(一个箭头操作符,因为要访问一个对象属性,你必须使用它)

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

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