Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查与其他数组包含相同值的php数组_Php_Arrays - Fatal编程技术网

如何检查与其他数组包含相同值的php数组

如何检查与其他数组包含相同值的php数组,php,arrays,Php,Arrays,我有两个数组,分别是$a和$b,其中数组的值相同,但元素的索引不同 $a Array ( [0] => there is bald spot on the inside or outside of tyre [1] => uneven tyre wear ) 但是当我使用$a==$b进行比较时,即使数组中的元素相同(只是元素的位置不同),它也会返回false 之前给出的解决方案是 $a = Array ( 0 => 'there is bald spot on t

我有两个数组,分别是
$a
$b
,其中数组的值相同,但元素的索引不同

$a 
Array ( [0] => there is bald spot on the inside or outside of tyre [1] => uneven tyre wear )
但是当我使用
$a==$b
进行比较时,即使数组中的元素相同(只是元素的位置不同),它也会返回
false

之前给出的解决方案是

$a = Array ( 
    0 => 'there is bald spot on the inside or outside of tyre',
    1 => 'uneven tyre wear'

);

$b = Array ( 
       0 => 'uneven tyre wear', 
       1 => 'there is bald spot on the inside or outside of tyre' 
    );

if(count(array_diff($a,$b)) == 0){
    echo "both array are identical";    

}
但是如果我从$a中删除一个元素

$a = Array ( 
    0 => 'there is bald spot on the inside or outside of tyre'
    //1 => 'uneven tyre wear'

);
如果使用上述解决方案,它仍然显示相同的结果。

使用

输出:-

注意:-如果两个数组大小不同(一个有多个元素,另一个有少个元素),那么在使用
array_diff()

检查此输出:-

使用数组_diff()


使用
数组_diff()
检查that@AnantSingh---AlivetoDie我刚刚发布到这个函数
$a = Array ( 
    0 => 'there is bald spot on the inside or outside of tyre'
    //1 => 'uneven tyre wear'

);
if(count(array_diff($a,$b)) == 0){
    echo "both array are identical";    

}
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");

$result=array_diff($a1,$a2)
print_r($result);
?>