在PHP多维数组中删除父级 [英] Remove Parent in PHP Multidimensional Array

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

问题描述

在多维数组中删除匹配键的父键的最佳方法是什么?例如,假设我们有以下数组,我想找到 [text] = a,然后删除其父数组[0] ...

What's the best way to remove the parent of a matched key in an Multidimensional Array? For example, let's assume we have the following array and I want to find "[text] = a" and then delete its parent array [0]...

(array) Array
(

[0] => Array
    (
        [text] => a
        [height] => 30
    )

[1] => Array
    (
        [text] => k
        [height] => 30
    )
)


推荐答案

很明显:

foreach ($array as $key => $item) {
    if ($item['text'] === 'a') {
        unset($array[$key]);
    }
}

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

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