PHP compare two dimension array

两盒软妹~` 提交于 2019-12-04 09:03:23
Amber
foreach($array1 as $k1 => $arrays) {
    foreach($arrays as $k2 => $val) {

        if($array2[$k1][$k2] == $val) {
            // $array1[$k1][$k2] is equal to $array2[$k1][$k2]
        }
    }
} // end of foreach

The foreach($a as $k => $v) syntax does the same thing as foreach($a as $v), except that it also puts the key associated with the value into $k.

You can use array_diff_assoclike so

if(count(array_diff_assoc($array1,array2) != 0))
{
   //Arrays are not the same
}else{
  echo 'these following items are differing in throughout the arrays . ' . print_r(array_diff_assoc($array1,array2),true);
}

Hope this helps you.

Also take note of array_diff_assoc, it returns the array items that are found to be different to the other array including its index keys.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!