1--TEST-- 2Test array_diff_assoc() function : usage variations - compare multidimensional arrays 3--FILE-- 4<?php 5/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) 6 * Description: Returns the entries of $arr1 that have values which are not 7 * present in any of the others arguments but do additional checks whether 8 * the keys are equal 9 * Source code: ext/standard/array.c 10 */ 11 12/* 13 * Test how array_diff_assoc behaves when comparing 14 * multi-dimensional arrays 15 */ 16 17echo "*** Testing array_diff_assoc() : usage variations ***\n"; 18 19$array1 = array('sub_array1' => array (1, 2, 3), 20 'sub_array2' => array ('a', 'b', 'c')); 21$array2 = array('sub_arraya' => array (1, 3, 5), 22 'sub_arrayb' => array ('a', 'z', 'y')); 23 24echo "-- Compare two 2-D arrays --\n"; 25var_dump(array_diff_assoc($array1, $array2)); 26var_dump(array_diff_assoc($array2, $array1)); 27 28echo "\n-- Compare subarrays from two 2-D arrays --\n"; 29var_dump(array_diff_assoc($array1['sub_array1'], $array2['sub_arraya'])); 30var_dump(array_diff_assoc($array2['sub_arraya'], $array1['sub_array1'])); 31var_dump(array_diff_assoc($array1['sub_array2'], $array2['sub_arrayb'])); 32var_dump(array_diff_assoc($array2['sub_arrayb'], $array1['sub_array1'])); 33 34echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; 35var_dump(array_diff_assoc($array1['sub_array1'], $array2)); 36var_dump(array_diff_assoc($array1, $array2['sub_arraya'])); 37 38echo "Done"; 39?> 40--EXPECTF-- 41*** Testing array_diff_assoc() : usage variations *** 42-- Compare two 2-D arrays -- 43array(2) { 44 ["sub_array1"]=> 45 array(3) { 46 [0]=> 47 int(1) 48 [1]=> 49 int(2) 50 [2]=> 51 int(3) 52 } 53 ["sub_array2"]=> 54 array(3) { 55 [0]=> 56 string(1) "a" 57 [1]=> 58 string(1) "b" 59 [2]=> 60 string(1) "c" 61 } 62} 63array(2) { 64 ["sub_arraya"]=> 65 array(3) { 66 [0]=> 67 int(1) 68 [1]=> 69 int(3) 70 [2]=> 71 int(5) 72 } 73 ["sub_arrayb"]=> 74 array(3) { 75 [0]=> 76 string(1) "a" 77 [1]=> 78 string(1) "z" 79 [2]=> 80 string(1) "y" 81 } 82} 83 84-- Compare subarrays from two 2-D arrays -- 85array(2) { 86 [1]=> 87 int(2) 88 [2]=> 89 int(3) 90} 91array(2) { 92 [1]=> 93 int(3) 94 [2]=> 95 int(5) 96} 97array(2) { 98 [1]=> 99 string(1) "b" 100 [2]=> 101 string(1) "c" 102} 103array(3) { 104 [0]=> 105 string(1) "a" 106 [1]=> 107 string(1) "z" 108 [2]=> 109 string(1) "y" 110} 111 112-- Compare a subarray from one 2-D array and one 2-D array -- 113array(3) { 114 [0]=> 115 int(1) 116 [1]=> 117 int(2) 118 [2]=> 119 int(3) 120} 121array(2) { 122 ["sub_array1"]=> 123 array(3) { 124 [0]=> 125 int(1) 126 [1]=> 127 int(2) 128 [2]=> 129 int(3) 130 } 131 ["sub_array2"]=> 132 array(3) { 133 [0]=> 134 string(1) "a" 135 [1]=> 136 string(1) "b" 137 [2]=> 138 string(1) "c" 139 } 140} 141Done 142