PHP - 检查两个数组相等, [英] PHP - Check if two arrays are equal

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

问题描述

我要检查,如果两个数组是相等的。我的意思是:相同的大小,相同的索引,相同的价值观。我该怎么做?

使用 === 由用户的建议,我希望下面将打印的输入如果阵列中的至少一个元素(多个)是不同的,但实际上并非如此。

  IF(($ _ POST ['atlOriginal']!=== $ oldAtlPosition)或($ _ POST ['ATL']!=== $ aext)或($ _ POST [ sidesOriginal']!=== $ oldSidePosition)或($ _ POST ['sidesOriginal']!=== $ sideext)){
    回声输入;
}


解决方案

  $ arraysAreEqual =($ A == $ b)条; // TRUE,如果$ a和$ b具有相同的键/值对。
$ arraysAreEqual =($ A $ === B); // TRUE,如果$ a和$ b具有相同的顺序和相同类型相同的键/值对。

请参阅数组运算

修改

不等式运算符是!= ,而非运营商的身份为!== 相匹配的平等
运营商 == 和运营商的身份 ===

I'd like to check if two arrays are equal. I mean: same size, same index, same values. How can I do that?

Using === as suggested by a user, I expect that the following would print enter if at least one element in the array(s) are different, but in fact it does not.

if(($_POST['atlOriginal']!===$oldAtlPosition) or ($_POST['atl']!===$aext) or ($_POST['sidesOriginal']!===$oldSidePosition) or ($_POST['sidesOriginal']!===$sideext)) {
    echo "enter";
}

解决方案

$arraysAreEqual = ($a == $b); // TRUE if $a and $b have the same key/value pairs.
$arraysAreEqual = ($a === $b); // TRUE if $a and $b have the same key/value pairs in the same order and of the same types.

See Array Operators.

EDIT

The inequality operator is != while the non-identity operator is !== to match the equality operator == and the identity operator ===.

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

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