And*_*res 7 php arrays multidimensional-array
删除多维数组中匹配键的父级的最佳方法是什么?例如,假设我们有以下数组,我想找到"[text] = a",然后删除它的父数组[0] ...
(array) Array
(
[0] => Array
(
[text] => a
[height] => 30
)
[1] => Array
(
[text] => k
[height] => 30
)
)
Run Code Online (Sandbox Code Playgroud)
这是显而易见的:
foreach ($array as $key => $item) {
if ($item['text'] === 'a') {
unset($array[$key]);
}
}
Run Code Online (Sandbox Code Playgroud)