Edit report at https://bugs.php.net/bug.php?id=63833&edit=1
ID: 63833 Updated by: ras...@php.net Reported by: francois dot dambrine at isen-lille dot fr Summary: diff doesn't compare properly inside arrays Status: Not a bug Type: Bug Package: Arrays related Operating System: Windows PHP Version: 5.5.0alpha2 Block user comment: N Private report: N New Comment: I still don't understand what you are asking about. array_diff being 1- dimensional means it doesn't look inside nested arrays at all. If you have a nested array, it treats it as if it was "Array" because it casts all elements in that dimension to its scalar equivalent. For example, these two are identical as far as array_diff() is concerned: $a = [ 1, 2, [3, 4] ]; $b = [ 1, 2, "Array" ]; Previous Comments: ------------------------------------------------------------------------ [2012-12-22 13:31:32] francois dot dambrine at isen-lille dot fr problem in the title ------------------------------------------------------------------------ [2012-12-22 13:30:18] francois dot dambrine at isen-lille dot fr I know it is multidimensional array. My problem is that if I want to compute the difference between those thwo multidimentional arrays. For now I can use array_udiff to get only the subarray with "lable"=>"Label1X" and Label2X, I have to use array_udiff even if when I test $A[0] == $B[0] I get true. So I was wondering if it was a bug or just a lack of precision in the documentation. If it is a documentation problem, I can go to edit.php.net ------------------------------------------------------------------------ [2012-12-22 13:01:54] ras...@php.net The documentation clearly states, "This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff($array1[0], $array2[0]);." Your example is using 2-dimensional arrays. ------------------------------------------------------------------------ [2012-12-22 12:38:38] francois dot dambrine at isen-lille dot fr Description: ------------ This bug was introduced to me by a stackoverflow post http://stackoverflow.com/questions/13815287/union-two-associative-array- php/13815578#13815578 I tested the behaviour with php 5.5 Alpha 2 and the "bug" is still there. As of the documentation, it is said that array_diff uses an "internal function" to compare two elements. As equality is the only thing that matters for array_diff I thought this internal function was something that "==" behind. But even if two arrays are equal (same members) array_diff does not take it in account. I mark it as a bug but it can only be a documentation problem. Test script: --------------- <?php $A = Array( array( 'lable' =>"label0", 'id_poste'=>1, 'id_part'=>11 ), array( 'lable' =>"label1", 'id_poste'=>2, 'id_part'=>12 ), array( 'lable' =>"label2", 'id_poste'=>3, 'id_part'=>13 ), array( 'lable' =>"label3", 'id_poste'=>4, 'id_part'=>14 ) ); $B = Array( array( 'lable' =>"label0", 'id_poste'=>1, 'id_part'=>11 ), array( 'lable' =>"label1_X", 'id_poste'=>2, 'id_part'=>12 ), array( 'lable' =>"label2", 'id_poste'=>3, 'id_part'=>13 ), array( 'lable' =>"label3_X", 'id_poste'=>4, 'id_part'=>14 ) ); var_dump(array_diff_assoc($B,$A)); Expected result: ---------------- Array(2){ [0]=>array(3){ ["lable"] =>"label1_X", ["id_poste"]=>2, ["id_part"]=>12 }, [1]=>array(3){ ["lable"] =>"label3_X", ["id_poste"]=>4, ["id_part"]=>14 } } Actual result: -------------- array(0){ } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63833&edit=1