PHP数组的比较 [英] PHP array comparison

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

问题描述

如何比较2阵列彼此?结果
例如,我有阵列(A,B,C)阵列(A,C,B )这将他们进行比较时返回true。但是,如果如果不是在其中一个发现的一个字母,将返回false。顺序并不重要。

How to compare 2 arrays with each other?
For example i have array("a", "b", "c") and array("a", "c", "b") It would return true when they're compared. But if one of the letters if not found in one of them it would return false. Order is not important.

推荐答案

您需要携带两个数组的内容转换成相同的顺序比较之前:

You need to bring the content of both arrays into the same order prior to comparison:

sort($array1);
sort($array2);
// now you can compare as usual
if ($array1 == $array2) ...

或者使用 ASORT()如果你想保持键。

Or use asort() if you want to maintain keys.

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

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