PHP:查找两个多维数组中的差异 [英] PHP: Finding differences in two multidimensional arrays

查看:557
本文介绍了PHP:查找两个多维数组中的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个数组

first array

Array
(
    [0] => Array
        (
            [file] => newhotfolder.gif
            [path] => images/newhotfolder.gif
            [type] => gif
            [size] => 1074
            [md5] => 123812asdkbqw98eqw80hasdas234234
        )

    [1] => Array
        (
            [file] => image.gif
            [path] => images/attachtypes/image.gif
            [type] => gif
            [size] => 625
            [md5] => 7bbb66e191688a86b6f42a03bd412a6b
        )

    [2] => Array
        (
            [file] => header.gif
            [path] => images/attachtypes/header.gif
            [type] => gif
            [size] => 625
            [md5] => 71291239asskf9320234kasjd8239393
        )
)





第二个数组





second array

Array
(
    [0] => Array
        (
            [file] => newhotfolder.gif
            [path] => images/newhotfolder.gif
            [type] => gif
            [size] => 1074
            [md5] => 8375h5910423aadbef67189c6b687ff51c
        )

    [1] => Array
        (
            [file] => image.gif
            [path] => images/attachtypes/image.gif
            [type] => gif
            [size] => 625
            [md5] => 7bbb66e191688a86b6f42a03bd412a6b
        )

    [2] => Array
        (
            [file] => footer.gif
            [path] => images/attachtypes/footer.gif
            [type] => gif
            [size] => 625
            [md5] => 1223819asndnasdn2213123nasd921
        )
)

推荐答案

这些是多维关联数组,您可以递归地执行array_diff_assoc,在此处查找:array-diff-assoc-php [
These are multi-dimensional associative arrays, you can recursively do an array_diff_assoc, find out here: array-diff-assoc-php[^]
See example:
<?php
/*
[NOTE BY danbrown AT php DOT net: The array_diff_assoc_recursive function is a 
combination of efforts from previous notes deleted.
Contributors included (Michael Johnson), (jochem AT iamjochem DAWT com), 
(sc1n AT yahoo DOT com), and (anders DOT carlsson AT mds DOT mdh DOT se).]
*/
function array_diff_assoc_recursive(


array1,


array2) { foreach(
array2) { foreach(


这篇关于PHP:查找两个多维数组中的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆