4 * Provides string comparison capability with support for appropriate
5 * locale-sensitive sort orderings.
7 <<__NativeData("Collator")>>
10 * Construct a new Collator instance
13 public function __construct(string $locale): void
;
16 * Sort array maintaining index association
18 * @param array $arr - Array of strings to sort.
19 * @param int $sort_flag - Optional sorting type, one of the following:
20 * Collator::SORT_REGULAR - compare items normally (don't change
21 * types) Collator::SORT_NUMERIC - compare items numerically
22 * Collator::SORT_STRING - compare items as strings Default
23 * $sort_flag value is Collator::SORT_REGULAR. It is also used if an
24 * invalid $sort_flag value has been specified.
29 public function asort(inout
mixed $arr,
30 int $sort_flag = Collator
::SORT_REGULAR
): bool;
33 * Compare two Unicode strings
35 * @param string $str1 - The first string to compare.
36 * @param string $str2 - The second string to compare.
38 * @return int - Return comparison result: 1 if str1 is greater
39 * than str2 ; 0 if str1 is equal to str2; -1 if str1 is less
40 * than str2 . On error boolean FALSE is returned.
43 public function compare(mixed $str1,
49 * @param string $locale - The locale containing the required collation
50 * rules. Special values for locales can be passed in - if null is
51 * passed for the locale, the default locale collation rules will be
52 * used. If empty string ("") or "root" are passed, UCA rules will be
55 * @return Collator - Return new instance of Collator object, or NULL
58 public static function create(string $locale): Collator
{
59 return new Collator($locale);
63 * Get collation attribute value
65 * @param int $attr - Attribute to get value for.
67 * @return int - Attribute value, or boolean FALSE on error.
70 public function getAttribute(int $attr): int;
73 * Get collator's last error code
75 * @return int - Error code returned by the last Collator API function
79 public function getErrorCode(): int;
82 * Get text for collator's last error code
84 * @return string - Description of an error occurred in the last
85 * Collator API function call.
88 public function getErrorMessage(): string;
91 * Get the locale name of the collator
93 * @param int $type - You can choose between valid and actual locale (
94 * Locale::VALID_LOCALE and Locale::ACTUAL_LOCALE, respectively).
96 * @return string - Real locale name from which the collation data
97 * comes. If the collator was instantiated from rules or an error
98 * occurred, returns boolean FALSE.
101 public function getLocale(int $type): string;
104 * Get sorting key for a string
106 * @param string $str - The string to produce the key from.
108 * @return string - Returns the collation key for the string. Collation
109 * keys can be compared directly instead of strings.
112 public function getSortKey(string $str): mixed;
115 * Get current collation strength
117 * @return int - Returns current collation strength, or boolean FALSE
121 public function getStrength(): int;
124 * Set collation attribute
126 * @param int $attr - Attribute.
127 * @param int $val - Attribute value.
132 public function setAttribute(int $attr,
136 * Set collation strength
138 * @param int $strength - Strength to set. Possible values are:
139 * Collator::PRIMARY Collator::SECONDARY Collator::TERTIARY
140 * Collator::QUATERNARY Collator::IDENTICAL
141 * Collator::DEFAULT_STRENGTH
146 public function setStrength(int $strength): bool;
149 * Sort array using specified collator and sort keys
151 * @param array $arr - Array of strings to sort
156 public function sortWithSortKeys(inout
mixed $arr): bool;
159 * Sort array using specified collator
161 * @param array $arr - Array of strings to sort.
162 * @param int $sort_flag - Optional sorting type, one of the following:
163 * Collator::SORT_REGULAR - compare items normally (don't change
164 * types) Collator::SORT_NUMERIC - compare items numerically
165 * Collator::SORT_STRING - compare items as strings Default sorting
166 * type is Collator::SORT_REGULAR. It is also used if an invalid
167 * sort_flag value has been specified.
172 public function sort(inout
mixed $arr,
173 int $sort_flag = Collator
::SORT_REGULAR
): bool;
177 * Sort array maintaining index association
179 * @param collator $coll - Collator object.
180 * @param array $arr - Array of strings to sort.
181 * @param int $sort_flag - Optional sorting type, one of the following:
182 * Collator::SORT_REGULAR - compare items normally (don't change types)
183 * Collator::SORT_NUMERIC - compare items numerically
184 * Collator::SORT_STRING - compare items as strings Default
185 * $sort_flag value is Collator::SORT_REGULAR. It is also used if an
186 * invalid $sort_flag value has been specified.
190 function collator_asort(collator
$coll,
192 int $sort_flag = Collator
::SORT_REGULAR
): bool {
193 return $coll->asort(inout
$arr, $sort_flag);
197 * Compare two Unicode strings
199 * @param collator $coll - Collator object.
200 * @param string $str1 - The first string to compare.
201 * @param string $str2 - The second string to compare.
203 * @return int - Return comparison result: 1 if str1 is greater than
204 * str2 ; 0 if str1 is equal to str2; -1 if str1 is less than
205 * str2 . On error boolean FALSE is returned.
207 function collator_compare(collator
$coll,
210 return $coll->compare($str1, $str2);
216 * @param string $locale - The locale containing the required collation
217 * rules. Special values for locales can be passed in - if null is passed
218 * for the locale, the default locale collation rules will be used. If
219 * empty string ("") or "root" are passed, UCA rules will be used.
221 * @return Collator - Return new instance of Collator object, or NULL on
224 function collator_create(string $locale): Collator
{
225 return Collator
::create($locale);
229 * Get collation attribute value
231 * @param collator $coll - Collator object.
232 * @param int $attr - Attribute to get value for.
234 * @return int - Attribute value, or boolean FALSE on error.
236 function collator_get_attribute(collator
$coll,
238 return $coll->getAttribute($attr);
242 * Get collator's last error code
244 * @param collator $coll - Collator object.
246 * @return int - Error code returned by the last Collator API function
249 function collator_get_error_code(collator
$coll): int {
250 return $coll->getErrorCode();
254 * Get text for collator's last error code
256 * @param collator $coll - Collator object.
258 * @return string - Description of an error occurred in the last Collator
261 function collator_get_error_message(collator
$coll): string {
262 return $coll->getErrorMessage();
266 * Get the locale name of the collator
268 * @param collator $coll - Collator object.
269 * @param int $type - You can choose between valid and actual locale (
270 * Locale::VALID_LOCALE and Locale::ACTUAL_LOCALE, respectively).
272 * @return string - Real locale name from which the collation data comes.
273 * If the collator was instantiated from rules or an error occurred,
274 * returns boolean FALSE.
276 function collator_get_locale(collator
$coll,
278 return $coll->getLocale($type);
282 * Get sorting key for a string
284 * @param collator $coll - Collator object.
285 * @param string $str - The string to produce the key from.
287 * @return string - Returns the collation key for the string. Collation
288 * keys can be compared directly instead of strings.
290 function collator_get_sort_key(collator
$coll,
291 string $str): string {
292 return $coll->getSortKey($str);
296 * Get current collation strength
298 * @param collator $coll - Collator object.
300 * @return int - Returns current collation strength, or boolean FALSE on
303 function collator_get_strength(collator
$coll): int {
304 return $coll->getStrength();
308 * Set collation attribute
310 * @param collator $coll - Collator object.
311 * @param int $attr - Attribute.
312 * @param int $val - Attribute value.
316 function collator_set_attribute(collator
$coll,
319 return $coll->setAttribute($attr, $val);
323 * Set collation strength
325 * @param collator $coll - Collator object.
326 * @param int $strength - Strength to set. Possible values are:
327 * Collator::PRIMARY Collator::SECONDARY Collator::TERTIARY
328 * Collator::QUATERNARY Collator::IDENTICAL
329 * Collator::DEFAULT_STRENGTH
333 function collator_set_strength(collator
$coll,
334 int $strength): bool {
335 return $coll->setStrength($strength);
339 * Sort array using specified collator and sort keys
341 * @param collator $coll - Collator object.
342 * @param array $arr - Array of strings to sort
346 function collator_sort_with_sort_keys(collator
$coll,
347 inout
mixed $arr): bool {
348 return $coll->sortWithSortKeys(inout
$arr);
352 * Sort array using specified collator
354 * @param collator $coll - Collator object.
355 * @param array $arr - Array of strings to sort.
356 * @param int $sort_flag - Optional sorting type, one of the following:
357 * Collator::SORT_REGULAR - compare items normally (don't change
358 * types) Collator::SORT_NUMERIC - compare items numerically
359 * Collator::SORT_STRING - compare items as strings Default sorting
360 * type is Collator::SORT_REGULAR. It is also used if an invalid
361 * sort_flag value has been specified.
365 function collator_sort(collator
$coll,
367 int $sort_flag = Collator
::SORT_REGULAR
): bool {
368 return $coll->sort(inout
$arr, $sort_flag);