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