douhui9380 2013-11-03 20:37
浏览 14
已采纳

删除关联数组的一部分[重复]

This question already has an answer here:

I want to search an associative array and when I find a value, delete that part of the array.

Here is a sample of my array:

    Array
(
    [0] => Array
        (
            [id] => 2918
            [schoolname] => Albany Medical College
            [AppService] => 16295C0C51D8318C2
        )

    [1] => Array
        (
            [id] => 2919
            [schoolname] => Albert Einstein College of Medicine
            [AppService] => 16295C0C51D8318C2
        )

    [2] => Array
        (
            [id] => 2920
            [schoolname] => Baylor College of Medicine
            [AppService] => 16295C0C51D8318C2
        )
}

What I want to do is find the value 16295C0C51D8318C2 in the AppService and then delete that part of the array. So, for example, if that code was to run on the above array, it was empty out the entire array since the logic matches everything in that array.

Here is my code so far:

            foreach($this->schs_raw as $object) {
                if($object['AppService'] == "16295C0C51D8318C2") {
                    unset($object);
                }
        }
</div>
  • 写回答

4条回答 默认 最新

  • dprlv04662 2013-11-03 20:39
    关注

    Try like this:

    foreach ($this->schs_raw as &$object) {
        if($object['AppService'] == "16295C0C51D8318C2") {
            unset($object);
        }
    }
    

    Eventually:

    foreach ($this->schs_raw as $k => $object) {
        if($object['AppService'] == "16295C0C51D8318C2") {
            unset($this->schs_raw[$k]);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!