1--TEST-- 2sort() 3--SKIPIF-- 4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> 5--FILE-- 6<?php 7 8/* 9 * Sort arrays using various locales. 10 */ 11 12 13$test_num = 1; 14 15/* 16 * Sort arrays in the given list using specified locale. 17 */ 18function sort_arrays( $locale, $arrays, $sort_flag = Collator::SORT_REGULAR ) 19{ 20 $res_str = ''; 21 22 $coll = ut_coll_create( $locale ); 23 24 foreach( $arrays as $array ) 25 { 26 // Sort array values 27 $res_val = ut_coll_sort( $coll, $array, $sort_flag ); 28 29 // Concatenate the sorted array and function result 30 // with output string. 31 $res_dump = "\n" . dump( $array ) . 32 "\n Result: " . dump( $res_val ); 33 34 // Preppend test signature to output string 35 $md5 = md5( $res_dump ); 36 37 global $test_num; 38 39 $res_str .= "\n\n". 40 "Test $test_num.$md5:" . 41 $res_dump; 42 ++$test_num; 43 } 44 45 return $res_str; 46} 47 48function ut_main() 49{ 50 global $test_num; 51 $test_num = 1; 52 $res_str = ''; 53 54 // Sort an array in SORT_REGULAR mode using en_US locale. 55 $test_params = array( 56 array( 'abc', 'abd', 'aaa' ), 57 array( 'm' , '1' , '_' ), 58 array( 'a' , 'aaa', 'aa' ), 59 array( 'ba' , 'b' , 'ab' ), 60 array( 'e' , 'c' , 'a' ), 61 array( '100', '25' , '36' ), 62 array( 5 , '30' , 2 ), 63 array( 'd' , '' , ' a' ), 64 array( 'd ' , 'f ' , ' a' ), 65 array( 'a' , null , '3' ), 66 array( 'y' , 'k' , 'i' ) 67 ); 68 69 $res_str .= sort_arrays( 'en_US', $test_params ); 70 71 $test_params = array( 72 array( '100', '25' , '36' ), 73 array( 5 , '30' , 2 ), 74 array( 'd' , '' , ' a' ), 75 array( 'y' , 'k' , 'i' ) 76 ); 77 78 // Sort in en_US locale with SORT_STRING flag 79 $res_str .= sort_arrays( 'en_US', $test_params, Collator::SORT_STRING ); 80 81 82 // Sort a non-ASCII array using ru_RU locale. 83 $test_params = array( 84 array( 'абг', 'абв', 'ааа', 'abc' ), 85 array( 'аа', 'ааа' , 'а' ) 86 ); 87 88 $res_str .= sort_arrays( 'ru_RU', $test_params ); 89 90 // Sort an array using Lithuanian locale. 91 $test_params = array( 92 array( 'y' , 'k' , 'i' ) 93 ); 94 95 $res_str .= sort_arrays( 'lt_LT', $test_params ); 96 97 return $res_str; 98} 99 100include_once( 'ut_common.inc' ); 101ut_run(); 102?> 103--EXPECT-- 104Test 1.e8f1cd28133d79ecd660002f1c660d0e: 105array ( 106 0 => 'aaa', 107 1 => 'abc', 108 2 => 'abd', 109) 110 Result: true 111 112Test 2.c2ded12173dd2996927378cae37eb275: 113array ( 114 0 => '_', 115 1 => '1', 116 2 => 'm', 117) 118 Result: true 119 120Test 3.54071c968d71cb98c5d379145f8d7d38: 121array ( 122 0 => 'a', 123 1 => 'aa', 124 2 => 'aaa', 125) 126 Result: true 127 128Test 4.19abe63d6f6dfef65b0e3c9ab4826b07: 129array ( 130 0 => 'ab', 131 1 => 'b', 132 2 => 'ba', 133) 134 Result: true 135 136Test 5.9a8dc0a9bc771368c2f1fc3d02754610: 137array ( 138 0 => 'a', 139 1 => 'c', 140 2 => 'e', 141) 142 Result: true 143 144Test 6.ab530b060e5e54a65bfb8b9f8fc61870: 145array ( 146 0 => '25', 147 1 => '36', 148 2 => '100', 149) 150 Result: true 151 152Test 7.0718dd838509017bded2ed307a6e785f: 153array ( 154 0 => 2, 155 1 => 5, 156 2 => '30', 157) 158 Result: true 159 160Test 8.923d65739c5219c634616ffd100a50e4: 161array ( 162 0 => '', 163 1 => ' a', 164 2 => 'd', 165) 166 Result: true 167 168Test 9.289bc2f28e87d3201ec9d7e8477ae1b0: 169array ( 170 0 => ' a', 171 1 => 'd ', 172 2 => 'f ', 173) 174 Result: true 175 176Test 10.de0fd958484f2377a645835d7fbcf124: 177array ( 178 0 => NULL, 179 1 => '3', 180 2 => 'a', 181) 182 Result: true 183 184Test 11.dd2b8f0adb37c45d528cad1a0cc0f361: 185array ( 186 0 => 'i', 187 1 => 'k', 188 2 => 'y', 189) 190 Result: true 191 192Test 12.1e6b4d6f7df9d4580317634ea46d8208: 193array ( 194 0 => '100', 195 1 => '25', 196 2 => '36', 197) 198 Result: true 199 200Test 13.cec115dc9850b98dfbdf102efa09e61b: 201array ( 202 0 => 2, 203 1 => '30', 204 2 => 5, 205) 206 Result: true 207 208Test 14.923d65739c5219c634616ffd100a50e4: 209array ( 210 0 => '', 211 1 => ' a', 212 2 => 'd', 213) 214 Result: true 215 216Test 15.dd2b8f0adb37c45d528cad1a0cc0f361: 217array ( 218 0 => 'i', 219 1 => 'k', 220 2 => 'y', 221) 222 Result: true 223 224Test 16.ca0e38a2e3147dd97070f2128f140934: 225array ( 226 0 => 'abc', 227 1 => 'ааа', 228 2 => 'абв', 229 3 => 'абг', 230) 231 Result: true 232 233Test 17.91480b10473a0c96a4cd6d88c23c577a: 234array ( 235 0 => 'а', 236 1 => 'аа', 237 2 => 'ааа', 238) 239 Result: true 240 241Test 18.fdd3fe3981476039164aa000bf9177f2: 242array ( 243 0 => 'i', 244 1 => 'y', 245 2 => 'k', 246) 247 Result: true 248