我想比较PHP两个数组 [英] I want to compare two arrays in PHP

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

问题描述

假设我有两个数组如下:

  $ ARRAY1 =阵列(1,3,5);
$数组2 =阵列('×'=大于1,'Y'=大于2,'Z'=大于5);

如何检查两个数组都完全相同,最有效和最适当的方式相同,它并不关心在 * $数组2的键名

我想打,如果值完全相同,应返回true的函数,假如果任何的人是不同的两种价值(S)和元素的个数。

感谢您的时间和阅读。


解决方案

  array_values​​($数组1)=== array_values​​($数组2)

假设数组具有相同的顺序。

Assume that I have two arrays as follow:

$array1 = array(1, 3, 5);
$array2 = array('x'=> 1, 'y'=> 2, 'z'=> 5);

How to check that the two arrays are exactly the same in most efficient and proper way and it doesn't care the keynames of the *$array2.

I want to make a function which should return true if values are exactly the same, and false if any of the ones are different both in value(s) and number of elements.

Thanks for your time and reading.

解决方案

 array_values($array1) === array_values($array2)

Assuming that arrays have same order.

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

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