PHP | Collator __construct() Function
Last Updated :
30 Aug, 2019
Improve
The Collator::__construct() function is an inbuilt function in PHP which is used to create a new instance of Collator.
Syntax:
php
php
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:
<?php
$coll = new Collator( 'en_CA' );
var_dump($coll);
?>
<?php
$coll = new Collator( 'en_CA' );
var_dump($coll);
?>
Output:
Program 2:
object(Collator)#1 (0) { }
<?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 );
?>
<?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 );
?>
Output:
Reference: https://www.php.net/manual/en/collator.construct.php
array ( 0 => 'geek', 1 => 'geeK', 2 => 'Geek', 3 => 'geeks', )