PHP:不区分大小写的“array_diff”
我有以下两个数组和查找 array_diff 的代码:
$obs_ws = array("you", "your", "may", "me", "my", "etc");
$all_ws = array("LOVE", "World", "Your", "my", "etc", "CoDe");
$final_ws = array_diff($all_ws, $obs_ws);
上面的代码给出的输出数组为:
$final_ws = array("LOVE", "World", "Your", "CoDe");
但我希望它为:
$final_ws = array("LOVE", "World", "CoDe");
注意“Your”没有被删除,这可能是因为“Y”在第二个数组中是大写的。我也想排除“Your”,那么PHP中是否有不区分大小写的array_diff
版本。
我尝试了 array_udiff 但我没有得到到底如何在我的问题中使用它
谢谢
I have following two arrays and the code to find array_diff:
$obs_ws = array("you", "your", "may", "me", "my", "etc");
$all_ws = array("LOVE", "World", "Your", "my", "etc", "CoDe");
$final_ws = array_diff($all_ws, $obs_ws);
Above code giving output array as:
$final_ws = array("LOVE", "World", "Your", "CoDe");
But I want it as:
$final_ws = array("LOVE", "World", "CoDe");
Note "Your" is not removed, it may be due to "Y" is in caps in second array. I want to exclude "Your" also, so is there any case-insensitive version of array_diff
in PHP.
I tried array_udiff but I am not getting exactly how to use this in my problem
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
strcasecmp
作为第三个参数传递给array_udiff
函数:输出:
Try to pass
strcasecmp
as third parameter toarray_udiff
function:Output:
你走在正确的轨道上。这是我的建议:
You were on the right track. This is my suggestion: