1--TEST-- 2asort() 3--EXTENSIONS-- 4intl 5--SKIPIF-- 6<?php if (version_compare(INTL_ICU_VERSION, '51.2') < 0) die('skip for ICU >= 51.2'); ?> 7--FILE-- 8<?php 9 10/* 11 * Sort associative arrays using various locales. 12 */ 13 14 15$test_num = 1; 16 17/* 18 * Sort various arrays in specified locale. 19 */ 20function sort_arrays( $locale, $test_arrays, $sort_flag = Collator::SORT_REGULAR ) 21{ 22 $res_str = ''; 23 24 $coll = ut_coll_create( $locale ); 25 26 foreach( $test_arrays as $test_array ) 27 { 28 // Try to sort test data. 29 $res_val = ut_coll_asort( $coll, $test_array, $sort_flag ); 30 31 // Return output data. 32 $res_dump = "\n" . dump( $test_array ) . 33 "\n Result: " . dump( $res_val ); 34 35 // Preppend test signature to output string 36 $md5 = md5( $res_dump ); 37 38 global $test_num; 39 40 $res_str .= "\n\n". 41 "Test $test_num.$md5:" . 42 $res_dump; 43 ++$test_num; 44 } 45 46 return $res_str; 47} 48 49/* 50 * Test main function. 51 */ 52function ut_main() 53{ 54 global $test_num; 55 $test_num = 1; 56 $res_str = ''; 57 58 // Sort an array in SORT_REGULAR mode using en_US locale. 59 $test_params = array( 60 array( 'd' => 'y' , 61 'c' => 'i' , 62 'a' => 'k' ), 63 64 array( 'a' => 'a' , 65 'b' => 'aaa', 66 'c' => 'aa' ), 67 68 array( 'a' => 'a' , 69 'aaa'=> 'a' , 70 'aa' => 'a' ), 71 72 array( '1' => 'abc', 73 '5' => '!' , 74 '2' => null , 75 '7' => '' ), 76 77 array( '1' => '100', 78 '2' => '25' , 79 '3' => '36' ), 80 81 array( '1' => 5 , 82 '2' => '30' , 83 '3' => 2 ) 84 ); 85 86 $res_str .= sort_arrays( 'en_US', $test_params ); 87 88 // Sort an array in SORT_STRING mode using en_US locale. 89 $test_params = array( 90 array( '1' => '100', 91 '2' => '25' , 92 '3' => '36' ), 93 94 array( '1' => 5 , 95 '2' => '30' , 96 '3' => 2 ), 97 98 array( '1' => 'd' , 99 '2' => '' , 100 '3' => ' a' ), 101 102 array( '1' => 'y' , 103 '2' => 'k' , 104 '3' => 'i' ) 105 ); 106 107 $res_str .= sort_arrays( 'en_US', $test_params, Collator::SORT_STRING ); 108 109 // Sort a non-ASCII array using ru_RU locale. 110 $test_params = array( 111 array( 'п' => 'у', 112 'б' => 'в', 113 'е' => 'а' ), 114 115 array( '1' => 'п', 116 '4' => '', 117 '7' => 'd', 118 '2' => 'пп' ) 119 ); 120 121 $res_str .= sort_arrays( 'ru_RU', $test_params ); 122 123 124 // Sort an array using Lithuanian locale. 125 $test_params = array( 126 array( 'd' => 'y', 127 'c' => 'i', 128 'a' => 'k' ) 129 ); 130 131 $res_str .= sort_arrays( 'lt_LT', $test_params ); 132 133 return $res_str . "\n"; 134} 135 136include_once( 'ut_common.inc' ); 137ut_run(); 138?> 139--EXPECT-- 140Test 1.162b81ac12878b817fc39063097e45b5: 141array ( 142 'c' => 'i', 143 'a' => 'k', 144 'd' => 'y', 145) 146 Result: true 147 148Test 2.93d96e22f692d8a281b0a389f01f8d1e: 149array ( 150 'a' => 'a', 151 'c' => 'aa', 152 'b' => 'aaa', 153) 154 Result: true 155 156Test 3.d5a9747a8bd4c32cb2a705f7e6d8a56f: 157array ( 158 'a' => 'a', 159 'aaa' => 'a', 160 'aa' => 'a', 161) 162 Result: true 163 164Test 4.dcc371022fa1eac76e73b0455d70790a: 165array ( 166 2 => NULL, 167 7 => '', 168 5 => '!', 169 1 => 'abc', 170) 171 Result: true 172 173Test 5.99dc71f405b286e03d489061b36e6900: 174array ( 175 2 => '25', 176 3 => '36', 177 1 => '100', 178) 179 Result: true 180 181Test 6.bf5bba243307c9d12934e756ad4be190: 182array ( 183 3 => 2, 184 1 => 5, 185 2 => '30', 186) 187 Result: true 188 189Test 7.e4ee7024c61476e9e7a6c28b5e47df6f: 190array ( 191 1 => '100', 192 2 => '25', 193 3 => '36', 194) 195 Result: true 196 197Test 8.5fa7033dd43784be0db1474eb48b83c8: 198array ( 199 3 => 2, 200 2 => '30', 201 1 => 5, 202) 203 Result: true 204 205Test 9.588cdf4692bc09aa92ffe7e48f9e4579: 206array ( 207 2 => '', 208 3 => ' a', 209 1 => 'd', 210) 211 Result: true 212 213Test 10.be02641a47ebcccd23e4183ca3a415f7: 214array ( 215 3 => 'i', 216 2 => 'k', 217 1 => 'y', 218) 219 Result: true 220 221Test 11.153d9b11d1e5936afc917a94a4e11f34: 222array ( 223 'е' => 'а', 224 'б' => 'в', 225 'п' => 'у', 226) 227 Result: true 228 229Test 12.e1f5cb037b564dce39ffbd0a61562d59: 230array ( 231 4 => '', 232 1 => 'п', 233 2 => 'пп', 234 7 => 'd', 235) 236 Result: true 237 238Test 13.8800d48abb960a59002eef77f1d73ae0: 239array ( 240 'c' => 'i', 241 'd' => 'y', 242 'a' => 'k', 243) 244 Result: true 245