Open In App

PHP | collator_sort() Function

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:



Parameters: This function accepts three parameters as mentioned above and described below:

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' );
  
// Declare array and initialize it
$arr  = array( 'geek', 'geeK', 'Geek', 'geeks' );
  
// Sort array
collator_sort( $coll, $arr );
  
// Display array content
var_export( $arr );
?>

Output:
array (
  0 => 'geek',
  1 => 'geeK',
  2 => 'Geek',
  3 => 'geeks',
)

Program 2:




<?php
$coll = collator_create( 'en_US' );
  
// Declare array and initialize it
$arr  = array( 30, 12, 56, 33, 74, 23, 1 );
  
// Sort array
collator_sort( $coll, $arr );
  
// Display array content
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


Article Tags :