duanjie2701 2013-10-29 08:55
浏览 61
已采纳

删除数组子项,其中value =多维数组中的某个值

I have a multidimentional array like this $membergroups :

Array ( [0] => 
    Array ( [id] => 1645819602 
        [name] => Oryza NurFa 
        [first_name] => Oryza 
        [last_name] => NurFa 
        [work] => MAN 2 Yogyakarta ) 
    [1] => 
    Array ( [id] => 100000251643877 
        [name] => Lathif Pambudi 
        [first_name] => Muhammad Lathif 
        [last_name] => Pambudi 
        [work] => Omah TI ) 
    [2] => 
    Array ( [id] => 1152078197 
        [name] => Novantio Bangun 
        [first_name] => Novantio 
        [last_name] => Bangun 
        [work] => Pertamina))

How to delete one of child array with specific value. For the example, I want to delete an array with [id] => 100000251643877 inside? So the output will be :

Array ( [0] => 
        Array ( [id] => 1645819602 
            [name] => Oryza NurFa 
            [first_name] => Oryza 
            [last_name] => NurFa 
            [work] => MAN 2 Yogyakarta ) 
        [1] => 
        Array ( [id] => 1152078197 
            [name] => Novantio Bangun 
            [first_name] => Novantio 
            [last_name] => Bangun 
            [work] => Pertamina))

Here is my php code, but it doesn't work :

if (($key = array_search($user_fbid, $membergroups)) !== false) {
   unset($membergroups[$key]);
}

Any help would be greatly appreciated. Thank you

  • 写回答

4条回答 默认 最新

  • dongzheng4556 2013-10-29 09:00
    关注

    Using a foreach you can do the job like this

    $id = 100000251643877;//Example
    foreach($membergroups as $key => $value){
      if($value['id'] == $id){
        unset($membergroups[$key]);  
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 刚接触VFP,我想知道为什么是这种情况,有人可以看看吗
  • ¥15 io.jsonwebtoken.security.Keys
  • ¥15 急,ubuntu安装后no caching mode page found等
  • ¥15 联想交换机NE2580O/NE1064TO安装SONIC
  • ¥15 防火墙的混合模式配置
  • ¥15 Ubuntu不小心注销了要怎么恢复啊
  • ¥15 win10电脑安装完plcsim advanced4.0运行时为什么会提示找不到虚拟网卡
  • ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
  • ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信