在PHP

时间:2017-07-15 10:17:16

标签: php

在数组中查找包含值的对象的最快方法是什么?

例如,我需要找到对象 orange 的数组索引(其索引 1 )。

(StandardClasses数组)

[
    {"apple":
        {"color" : "green", "shape" : "round"}
    },

    {"orange":
        {"color" : "orange", "shape" : "round"}
    },

    {"banana":
        {"color" : "yellow", "shape" : "long"}
    }
]

1 个答案:

答案 0 :(得分:-1)

无需为每个声明找到索引用户更清洁 foreach语句将在您的数组中循环

foreach(var item in YourArray){//do your logic here}