douhua1890 2010-11-12 15:33
浏览 90
已采纳

在给定属性值的对象数组中查找数组键

I have an objects array like this:

Array
(
    [945] => member Object
        (
            [id] => 13317
            [name] => Test 999
            [last_name] => Test 999
        )

    [54] => member Object
        (
            [id] => 13316
            [name] => Manuel
            [last_name] => Maria parra
        )

    [654] => member Object
        (
            [id] => 13315
            [name] => Byron 
            [last_name] => Castillo
        )

    [656] => member Object
        (
            [id] => 13314
            [name] => Cesar
            [last_name] => Vasquez
        )
)

I need to remove one of these objects according to an attribute value.
For example, I want to remove from the array the object id 13316.

  • 写回答

5条回答 默认 最新

  • dsh12544 2010-11-12 15:44
    关注

    Here is the functional approach:

    $neededObjects = array_filter(
        $objects,
        function ($e) {
            return $e->id != 13316;
        }
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?