PHP | Collator __construct() Function

The Collator::__construct() function is an inbuilt function in PHP which is used to create a new instance of Collator.

Syntax:

public Collator::__construct( string $locale )

Parameters: This function accepts single parameter $locale which holds the collation rules. If a null value is passed for the locale, the default locale collation rules will be used. If empty string (“”) or “root” are passed in the locale then UCA rules will be used.

Return Value: This function returns the Collator instance.

Below programs illustrate the Collator::__construct() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
$coll = new Collator( 'en_CA' );
  
var_dump($coll);
?>

chevron_right


Output:

object(Collator)#1 (0) {
}

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
$coll = new Collator( 'en_CA' );
  
// Declare array and initialize it 
$arr = array( 'geek', 'geeK', 'Geek', 'geeks' ); 
   
// Sort array 
collator_sort( $coll, $arr ); 
   
// Display array content 
var_export( $arr ); 
?> 

chevron_right


Output:

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

Reference: https://www.php.net/manual/en/collator.construct.php

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.