是否有一个PHP函数删除任何/有从数组一定值的所有键/值对? [英] Is there a PHP function to remove any/all key/value pairs that have a certain value from an array?

查看:108
本文介绍了是否有一个PHP函数删除任何/有从数组一定值的所有键/值对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得像这样的问题是,为什么我不喜欢使用PHP工作的原因。该手册是很好的,如果你能找到你所寻找的。通过阵列功能的看完之后,我没有看到一个提供我所需要的功能。

I think questions like this are the reason why I don't like working with PHP. The manual is good, if you can find what you are looking for. After reading through the Array Functions, I didn't see one that provides the functionality I need.

我有我要扫描特定值的数组(在我的情况下,数字索引),如果它的存在,将其删除。然后,当该值的所有实例已被删除,我想用的 array_values​​ 的。

I have an array (in my case, numerically indexed) that I want to scan for a particular value and, if it's there, remove it. And then, when all instances of that value have been removed, I want to rearrange the array using array_values.

推荐答案

和array_diff 是你想要的。

array_diff is what you want.

$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

结果:蓝色

这篇关于是否有一个PHP函数删除任何/有从数组一定值的所有键/值对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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