How to find index of object in php array?

前端 未结 10 1928
时光说笑
时光说笑 2021-02-13 18:46

Here is print_r output of my array:

Array
(
[0] => stdClass Object
    (
        [itemId] => 560639000019
        [name] => Item no1
        [code] =>         


        
10条回答
  •  猫巷女王i
    2021-02-13 19:40

    Another way to achieve the result is to use array_filter.

    $array = array(
        (object)array('id' => 5),
        (object)array('id' => 4),
        (object)array('id' => 3)
    );
    $array = array_filter($array, function($item) {
        return $item->id != 4;
    });
    print_r($array);
    

提交回复
热议问题