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