PHP | collator_sort_with_sort_keys() Function
The collator_sort_with_sort_keys() function is an inbuilt function in PHP which is used to sort array using specified collator and sort keys.
Syntax:
Parameters: This function accepts two parameters as mentioned above and described below:
- $coll: This parameter is used as collator object. It provides the comparison capability with support for appropriate locale-sensitive sort orderings.
- $arr: This parameter is used to hold the string which needs to sort.
Return Value: This function returns True on success or False on failure.
Below programs illustrates the collator_sort_with_sort_keys() function in PHP.
Program 1:
<?php
$arr = array ( 'Geeks' , 'g4g' , 'GeeksforGeeks' , 'geek' );
$coll = collator_create( 'gs' );
collator_sort_with_sort_keys( $coll , $arr );
var_export( $arr );
?>
|
Output:
array (
0 => 'g4g',
1 => 'geek',
2 => 'Geeks',
3 => 'GeeksforGeeks',
)
Program 2:
<?php
$arr = array ( 'Geeks123' , 'GeeksABC' , 'GeeksforGeeks' , 'Geeks' );
$coll = collator_create( 'en_US' );
collator_sort_with_sort_keys( $coll , $arr );
var_export( $arr );
?>
|
Output:
array (
0 => 'Geeks',
1 => 'Geeks123',
2 => 'GeeksABC',
3 => 'GeeksforGeeks',
)
Reference: http://php.net/manual/en/collator.sortwithsortkeys.php
Last Updated :
29 Oct, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...