1--TEST-- 2Test ksort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) 3--FILE-- 4<?php 5/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) 6 * Description: Sort an array by key, maintaining key to data correlation. 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * testing ksort() by providing array of mixed values for $array argument with following flag values: 12 * 1.flag value as defualt 13 * 2.SORT_REGULAR - compare items normally 14*/ 15 16echo "*** Testing ksort() : usage variations ***\n"; 17 18// mixed value array with different key values 19$mixed_values = array ( 20 "array1" => array(), 21 "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), 22 "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() 23 ), 24 4 => 4, "4" => "4", 4.01 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2.01 => -2.01, 25 -2.98989 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, 26 "ab" => "ab", "abcd" => "abcd", 0.01 => 0.01, -0 => -0, '' => '' , 27 "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0.001 => 0.001 28); 29 30echo "\n-- Testing ksort() by supplying mixed value array, 'flag' value is defualt --\n"; 31$temp_array = $mixed_values; 32var_dump( ksort($temp_array) ); 33var_dump($temp_array); 34 35echo "\n-- Testing ksort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; 36$temp_array = $mixed_values; 37var_dump( ksort($temp_array, SORT_REGULAR) ); 38var_dump($temp_array); 39 40echo "Done\n"; 41?> 42--EXPECTF-- 43*** Testing ksort() : usage variations *** 44 45-- Testing ksort() by supplying mixed value array, 'flag' value is defualt -- 46bool(true) 47array(13) { 48 [-2]=> 49 float(-2.98989) 50 [""]=> 51 string(0) "" 52 ["-.9"]=> 53 string(3) "-.9" 54 ["True"]=> 55 string(4) "True" 56 ["ab"]=> 57 string(2) "ab" 58 ["abcd"]=> 59 string(4) "abcd" 60 ["array1"]=> 61 array(0) { 62 } 63 ["array2"]=> 64 array(4) { 65 ["sub_array[2,1]"]=> 66 array(3) { 67 [0]=> 68 int(33) 69 [1]=> 70 int(-5) 71 [2]=> 72 int(6) 73 } 74 ["sub_array[2,2]"]=> 75 array(1) { 76 [0]=> 77 int(11) 78 } 79 ["sub_array[2,3]"]=> 80 array(2) { 81 [0]=> 82 int(22) 83 [1]=> 84 int(-55) 85 } 86 ["sub_array[2,4]"]=> 87 array(0) { 88 } 89 } 90 ["b"]=> 91 string(1) "b" 92 [0]=> 93 float(0.001) 94 ["abcdabcdabcd"]=> 95 string(14) "abcdabcdabcd" 96 [4]=> 97 float(4.01) 98 [5]=> 99 string(1) "5" 100} 101 102-- Testing ksort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- 103bool(true) 104array(13) { 105 [-2]=> 106 float(-2.98989) 107 [""]=> 108 string(0) "" 109 ["-.9"]=> 110 string(3) "-.9" 111 ["True"]=> 112 string(4) "True" 113 ["ab"]=> 114 string(2) "ab" 115 ["abcd"]=> 116 string(4) "abcd" 117 ["array1"]=> 118 array(0) { 119 } 120 ["array2"]=> 121 array(4) { 122 ["sub_array[2,1]"]=> 123 array(3) { 124 [0]=> 125 int(33) 126 [1]=> 127 int(-5) 128 [2]=> 129 int(6) 130 } 131 ["sub_array[2,2]"]=> 132 array(1) { 133 [0]=> 134 int(11) 135 } 136 ["sub_array[2,3]"]=> 137 array(2) { 138 [0]=> 139 int(22) 140 [1]=> 141 int(-55) 142 } 143 ["sub_array[2,4]"]=> 144 array(0) { 145 } 146 } 147 ["b"]=> 148 string(1) "b" 149 [0]=> 150 float(0.001) 151 ["abcdabcdabcd"]=> 152 string(14) "abcdabcdabcd" 153 [4]=> 154 float(4.01) 155 [5]=> 156 string(1) "5" 157} 158Done 159