1--TEST-- 2collator_get_sort_key() 3--EXTENSIONS-- 4intl 5--SKIPIF-- 6<?php /* XXX Obviously it fails somewhere between >= 4.8 and < 51.2 */ 7if (version_compare(INTL_ICU_VERSION, '51.2') >= 0) die('skip for ICU < 51.2'); ?> 8--FILE-- 9<?php 10 11/* 12 * Get sort keys using various locales 13 */ 14function sort_arrays( $locale, $data ) 15{ 16 $res_str = ''; 17 18 $coll = ut_coll_create( $locale ); 19 20 foreach($data as $value) { 21 $res_val = ut_coll_get_sort_key( $coll, $value ); 22 $res_str .= "source: ".$value."\n". 23 "key: ".bin2hex($res_val)."\n"; 24 } 25 26 return $res_str; 27} 28 29 30function ut_main() 31{ 32 $res_str = ''; 33 34 // Regular strings keys 35 $test_params = array( 36 'abc', 'abd', 'aaa', 37 'аа', 'а', 'z', 38 '', null , '3', 39 'y' , 'i' , 'k' 40 ); 41 42 $res_str .= sort_arrays( 'en_US', $test_params ); 43 44 // Sort a non-ASCII array using ru_RU locale. 45 $test_params = array( 46 'абг', 'абв', 'жжж', 'эюя' 47 ); 48 49 $res_str .= sort_arrays( 'ru_RU', $test_params ); 50 51 // Sort an array using Lithuanian locale. 52 $res_str .= sort_arrays( 'lt_LT', $test_params ); 53 54 return $res_str . "\n"; 55} 56 57include_once( 'ut_common.inc' ); 58ut_run(); 59?> 60--EXPECT-- 61source: abc 62key: 27292b01070107 63source: abd 64key: 27292d01070107 65source: aaa 66key: 27272701070107 67source: аа 68key: 5c0a0a01060106 69source: а 70key: 5c0a01050105 71source: z 72key: 5901050105 73source: 74key: 0101 75source: 76key: 0101 77source: 3 78key: 1801050105 79source: y 80key: 5701050105 81source: i 82key: 3701050105 83source: k 84key: 3b01050105 85source: абг 86key: 5c0a161a01070107 87source: абв 88key: 5c0a161801070107 89source: жжж 90key: 5c3a3a3a01070107 91source: эюя 92key: 5d3b3f4501070107 93source: абг 94key: 5c0a161a01070107 95source: абв 96key: 5c0a161801070107 97source: жжж 98key: 5c3a3a3a01070107 99source: эюя 100key: 5d3b3f4501070107 101