如何比较拼接的多维数组(具有大量数据)?

How can I compare spliced multidimensional arrays (with huge amount of data)?

我有一个巨大的数组 $properties,其中包含大约 500.000 个项目:

  array(470000) {
    ["12345"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 19:46:25"
      ["fileName"]=>
      string(46) "monkey.jpg"
      ["path"]=>
      string(149) "Volumes/animals/monkey.jpg"
      ["size"]=>
      string(7) "2650752"
    }
    ["678790"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 14:39:43"
      ["fileName"]=>
      string(45) "elephant.jpg"
      ["path"]=>
      string(171) "Volumes/animals/elephant.jpg"
      ["size"]=>
      string(7) "2306688"
    }

... and so on.

所以为了性能更好,我把它拼接成几个部分:

$splice_size = 10000;
        $count_arr = (count($properties)/$splice_size)-1;


        For($i=0; $i<$count_arr; $i++){
            $res[] = array_splice($properties, 0,$splice_size); 
        }
        $res[] = array_splice($properties, 0,count($properties)); 

现在我的数组如下所示:

array(4) {
  [0]=>
  array(10000) {
    ["12345"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 19:46:25"
      ["fileName"]=>
      string(46) "monkey.jpg"
      ["path"]=>
      string(149) "Volumes/animals/monkey.jpg"
      ["size"]=>
      string(7) "2650752"
    }
    ["678790"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 14:39:43"
      ["fileName"]=>
      string(45) "elephant.jpg"
      ["path"]=>
      string(171) "Volumes/animals/elephant.jpg"
      ["size"]=>
      string(7) "2306688"
    }

   ... and so on.
   }
  [1]=>....
  and so on....
}

我现在想比较其中两个数组:

  function array_diff_assoc_recursive($array1, $array2)
                {
                    foreach($array1 as $key => $value)
                    {
                        if(is_array($value))
                        {
                            if(!isset($array2[$key]))
                            {
                                $difference[$key] = $value;
                            }
                            elseif(!is_array($array2[$key]))
                            {
                                $difference[$key] = $value;
                            }
                            else
                            {
                                $new_diff = array_diff_assoc_recursive($value, $array2[$key]);
                                if($new_diff != FALSE)
                                {
                                    $difference[$key] = $new_diff;
                                }
                            }
                        }
                        elseif(!isset($array2[$key]) || $array2[$key] != $value)
                        {
                            $difference[$key] = $value;
                        }
                    }
                    return !isset($difference) ? 0 : $difference;
                }


                echo "<pre>";
                print_r(array_diff_assoc_recursive($new, $res));
                echo "</pre>";

但是系统崩溃了。数据太多。所以我的问题是,它们一定是拼接数组(比如制作块)的优势,我仍然没有得到,以获得更好的性能。

如果我是你,我会这样做:

$different = [];
$missingFrom2 = [];

foreach ($array1 as $key => $value) {
    if (!isset($array2[$key])) { $missingFrom2[] = $key; }
    if ($array2[$key] != $value) { $different[] = $key; }
}
$missingFrom1 = array_diff(array_keys($array2), array_keys($array1));

$different 将是所有不同的键。

你所做的似乎有点过度设计,没有什么特别的好处

示例:http://sandbox.onlinephpfunctions.com/code/7ff02f562e0591e8afb45ea51799b847fbc4063b http://sandbox.onlinephpfunctions.com/code/402926605ba8a195d2dfc667be146654117cd078