PHP Difference of two assoc Arrays -
i have 2 arrays of assoc arrays:
first one:
array ( [0] => array ( [24] => s [23] => czarny ) [1] => array ( [24] => m [23] => czarny ) [2] => array ( [24] => l [23] => czarny ) )
and second:
array ( [0] => array ( [24] => l [23] => czarny ) [1] => array ( [23] => czarny [24] => m ) )
in output get:
array ( [24] => s [23] => czarny )
because 2 of arrays:
[0] => array ( [23] => czarny [24] => m )
and
[0] => array ( [24] => m [23] => czarny )
are same me. have idea how deal that? tried fourth nested foreach got confused..
this little loop crazy, work.
$array1[0][23] = 'czarny'; $array1[0][24] = 'm'; $array1[1][23] = 'czarny'; $array1[1][24] = 's'; $array1[2][23] = 'czarny'; $array1[2][24] = 'l'; $array2[0][23] = 'czarny'; $array2[0][24] = 'm'; $array2[1][23] = 'czarny'; $array2[1][24] = 'l'; end($array1); // merge 2 arrays $array3 = array_merge($array1,$array2); // loop through 1 array , create second assoc array based on key 24 foreach($array1 $mainkey => $object) { foreach($object $key => $value) { $newarray[$object[24]][$key] = $value; } } // loop through new array create yet new 1 reset keys numeric $i=0; foreach($newarray $key => $value) { $final[$i] = $value; $i++; } print_r($final);
Comments
Post a Comment