How to search by a property in array of objects in php?

后端 未结 3 997
闹比i
闹比i 2021-01-28 13:06

i have an array something like given below is it possible to find the key index of the array if i provide a slab id value in php?

Array
       (
           [0         


        
3条回答
  •  悲&欢浪女
    2021-01-28 13:19

    Something like that :

    function getIndex($array, $slabId) {
        foreach($array as $index => $item) {
            if($item->slabId == $slabId)
                return $index;
        }
    }
    

提交回复
热议问题