1--TEST-- 2sort_with_sort_keys() 3--SKIPIF-- 4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> 5<?php if (version_compare(INTL_ICU_VERSION, '51.2') >= 0) die('skip for ICU < 51.2'); ?> 6--FILE-- 7<?php 8 9/* 10 * Sort arrays using various locales. 11 */ 12 13 14$test_num = 1; 15 16/* 17 * Sort arrays in the given list using specified locale. 18 */ 19function sort_arrays( $locale, $arrays ) 20{ 21 $res_str = ''; 22 23 $coll = ut_coll_create( $locale ); 24 25 foreach( $arrays as $array ) 26 { 27 // Sort array values 28 $res_val = ut_coll_sort_with_sort_keys( $coll, $array ); 29 30 // Concatenate the sorted array and function result 31 // with output string. 32 $res_dump = "\n" . dump( $array ) . 33 "\n Result: " . dump( $res_val ); 34 35 36 // Preppend test signature to output string 37 $md5 = md5( $res_dump ); 38 39 global $test_num; 40 41 $res_str .= "\n\n". 42 "Test $test_num.$md5:" . 43 $res_dump; 44 ++$test_num; 45 } 46 47 return $res_str; 48} 49 50 51function ut_main() 52{ 53 global $test_num; 54 $test_num = 1; 55 $res_str = ''; 56 57 // Sort an array in SORT_REGULAR mode using en_US locale. 58 $test_params = array( 59 array( 'abc', 'abd', 'aaa' ), 60 array( 'm' , '1' , '_' ), 61 array( 'a' , 'aaa', 'aa' ), 62 array( 'ba' , 'b' , 'ab' ), 63 array( 'e' , 'c' , 'a' ), 64 array( 'd' , '' , ' a' ), 65 array( 'd ' , 'f ' , ' a' ), 66 array( 'a' , null , '3' ), 67 array( 'y' , 'i' , 'k' ) 68 ); 69 70 $res_str .= sort_arrays( 'en_US', $test_params ); 71 72 // Sort a non-ASCII array using ru_RU locale. 73 $test_params = array( 74 array( 'абг', 'абв', 'ааа', 'abc' ), 75 array( 'аа', 'ааа', 'а' ) 76 ); 77 78 $res_str .= sort_arrays( 'ru_RU', $test_params ); 79 80 // Array with data for sorting. 81 $test_params = array( 82 array( 'y' , 'i' , 'k' ) 83 ); 84 85 // Sort an array using Lithuanian locale. 86 $res_str .= sort_arrays( 'lt_LT', $test_params ); 87 88 return $res_str . "\n"; 89} 90 91include_once( 'ut_common.inc' ); 92ut_run(); 93?> 94--EXPECT-- 95Test 1.e8f1cd28133d79ecd660002f1c660d0e: 96array ( 97 0 => 'aaa', 98 1 => 'abc', 99 2 => 'abd', 100) 101 Result: true 102 103Test 2.c2ded12173dd2996927378cae37eb275: 104array ( 105 0 => '_', 106 1 => '1', 107 2 => 'm', 108) 109 Result: true 110 111Test 3.54071c968d71cb98c5d379145f8d7d38: 112array ( 113 0 => 'a', 114 1 => 'aa', 115 2 => 'aaa', 116) 117 Result: true 118 119Test 4.19abe63d6f6dfef65b0e3c9ab4826b07: 120array ( 121 0 => 'ab', 122 1 => 'b', 123 2 => 'ba', 124) 125 Result: true 126 127Test 5.9a8dc0a9bc771368c2f1fc3d02754610: 128array ( 129 0 => 'a', 130 1 => 'c', 131 2 => 'e', 132) 133 Result: true 134 135Test 6.923d65739c5219c634616ffd100a50e4: 136array ( 137 0 => '', 138 1 => ' a', 139 2 => 'd', 140) 141 Result: true 142 143Test 7.289bc2f28e87d3201ec9d7e8477ae1b0: 144array ( 145 0 => ' a', 146 1 => 'd ', 147 2 => 'f ', 148) 149 Result: true 150 151Test 8.de0fd958484f2377a645835d7fbcf124: 152array ( 153 0 => NULL, 154 1 => '3', 155 2 => 'a', 156) 157 Result: true 158 159Test 9.dd2b8f0adb37c45d528cad1a0cc0f361: 160array ( 161 0 => 'i', 162 1 => 'k', 163 2 => 'y', 164) 165 Result: true 166 167Test 10.ca0e38a2e3147dd97070f2128f140934: 168array ( 169 0 => 'abc', 170 1 => 'ааа', 171 2 => 'абв', 172 3 => 'абг', 173) 174 Result: true 175 176Test 11.91480b10473a0c96a4cd6d88c23c577a: 177array ( 178 0 => 'а', 179 1 => 'аа', 180 2 => 'ааа', 181) 182 Result: true 183 184Test 12.fdd3fe3981476039164aa000bf9177f2: 185array ( 186 0 => 'i', 187 1 => 'y', 188 2 => 'k', 189) 190 Result: true 191