搜索和多维数组中删除 [英] Search and remove from multidimensional array

查看:99
本文介绍了搜索和多维数组中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我价值ID等于1,搜索一个数组我喜欢从阵列本身在那里如发现ID为1删除。

If I a value ID equals 1 and search an array I like to remove from the array itself where ID is 1 if found.

Array (
[0] => Array
    (
        [id] => 1
    )
[1] => Array
    (
        [id] => 4
    )
[2] => Array
    (
        [id] => 5
    )
[3] => Array
    (
        [id] => 7
    )
)

新的数组

Array (
[0] => Array
    (
        [id] => 4
    )
[1] => Array
    (
        [id] => 5
    )
[2] => Array
    (
        [id] => 7
    )
)

我使用search_array,和我假设,因为它是多维的是没有找到它。有没有一种方法来搜索一个数组像上面?

I am using search_array, and I am assuming that because it is multidimensional it isn't finding it. Is there a way to search an array like above?

推荐答案

如果你只是检查一个值,为什么不使用foreach循环?

If you just checking a single value, why not just use a foreach loop?

foreach ( $arr as $key => $value )
  {
    if ( $value['id'] == '1' )
      {
        unset( $arr[$key] );
      }
  }

这篇关于搜索和多维数组中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆