gpt4 book ai didi

PHP - 检查两个数组是否相等

转载 作者:IT老高 更新时间:2023-10-28 11:38:48 25 4
gpt4 key购买 nike

我想检查两个数组是否相等。我的意思是:相同的大小、相同的索引、相同的值。我该怎么做?

按照用户的建议使用 !==,如果数组中至少有一个元素不同,我希望以下内容会打印 enter,但是事实上它没有。

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.

Array Operators .

编辑

不等运算符是 != 而非恒等运算符是 !== 以匹配相等运算符 == 和身份运算符 ===

关于PHP - 检查两个数组是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5678959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com