PHP | collator_sort() Function
Last Updated :
21 Sep, 2018
The collator_sort() function is an inbuilt function in PHP which is used to sort an array using specified collator. This function returns True on success or False on failure.
Syntax:
- Procedural style:
bool collator_sort( $coll, $arr, $sort_flag )
- Object oriented style:
bool Collator::sort( $arr, $sort_flag )
Parameters: This function accepts three parameters as mentioned above and described below:
- $coll: This parameter is used as collator object.
- $arr: This parameter contains array of which needs to sort.
- $sort_flag: It is optional parameter which define sorting type, one of the following:
- Collator::SORT_REGULAR: It compare items normally. It is the default sorting.
- Collator::SORT_NUMERIC: It compare the items numerically.
- Collator::SORT_STRING: It compare the items as strings.
Return Value: This function returns True on success or false on failure.
Below programs illustrate the collator_sort() function in PHP:
Program 1:
<?php
$coll = collator_create( 'en_US' );
$arr = array ( 'geek' , 'geeK' , 'Geek' , 'geeks' );
collator_sort( $coll , $arr );
var_export( $arr );
?>
|
Output:
array (
0 => 'geek',
1 => 'geeK',
2 => 'Geek',
3 => 'geeks',
)
Program 2:
<?php
$coll = collator_create( 'en_US' );
$arr = array ( 30, 12, 56, 33, 74, 23, 1 );
collator_sort( $coll , $arr );
var_export( $arr );
?>
|
Output:
array (
0 => 1,
1 => 12,
2 => 23,
3 => 30,
4 => 33,
5 => 56,
6 => 74,
)
Related Articles:
Reference: http://php.net/manual/en/collator.sort.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...