开发者社区> 问答> 正文

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

我有两个数组,分别是$a和$b,其中数组的值相同,但元素的索引不同。 $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 ) 但是当我使用进行比较时$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'

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

展开
收起
社区秘书 2019-12-09 16:26:58 571 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载