简体   繁体   English

一般比较两个php数组

[英]comparing two php arrays in general

Supposed we have: 假设我们有:

$arr1 = array("a", "b");
$arr2 = array("a", "b");

and arrays are always sorted. 并且数组总是排序的。 Is this true: 这是真的:

if ( $arr1 === $arr2 )
{
     echo "condition met";
}

You can compare two (and more) arrays with array_diff() and look for an empty array, in your case. 您可以将两个(和更多个)数组与array_diff()进行比较 ,以查找空数组。

$diff = array_diff($arr1, $arr2);
if(empty($diff)) {
    echo "condition met";
}
($arr1 == $arr2); // TRUE when both  have the same key/value pairs.
($arr1 === $arr2); // TRUE when both have the same key/value pairs in the same order and of the same types.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM