PHP关联数组访问

时间:2016-08-09 22:51:56

标签: php arrays associative-array

我有一个像下面这样的关联数组,实际的数组要大得多。这只是其中的一部分。我想访问 “[equipmentType] => WARRANTY”的元素。在这种情况下,元素编号为[39],但元素编号会发生变化,但并不总是[39]。

我知道我可以访问$ arrayName [“equipment”] [“39”] [“name”]但是如果它不是[39]我该如何访问它?

在这个特定示例中,您可以使用[equipmentCount]值看到44个元素。

如果我没有解释清楚,我道歉。

Array
(
    [equipment] => Array
    (

        [2] => Array
            (
                [id] => 20073207920
                [name] => Mobile Connectivity
                [equipmentType] => OTHER
                [availability] => STANDARD
                [attributes] => Array
                    (
                        [0] => Array
                            (
                                [name] => Bluetooth
                                [value] => Bluetooth
                            )

                    )

            )

        [39] => Array
            (
                [id] => 200732343
                [name] => Rust, 5 Years,  /U Miles
                [equipmentType] => WARRANTY
                [availability] => STANDARD
                [attributes] => Array
                    (
                        [0] => Array
                            (
                                [name] => Warranty End Date
                                [value] => 09-Sep-2099
                            )
                    )

            )

    )

    [equipmentCount] => 44
)

谢谢!

1 个答案:

答案 0 :(得分:1)

如果我理解正确,也许这就是你想要的:

glm