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