PHP | collator_compare() Function Last Updated : 20 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The collator_compare() function is an inbuilt function in PHP which is used to compare two Unicode strings according to collation rules. Syntax: Procedural style: int collator_compare( $coll, $str1, $str2 ) Object oriented style: int Collator::compare( $str1, $str2 ) Parameters: This function accepts three parameter 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. $str1: The first string to compare. $str2: The second string to compare. Return Value: This function returns the comparison result which are given below: 1: If str1 is greater than str2. 0: If str1 is equal to str2. -1: If str1 is less than str2. Error: It return False. Below programs illustrate the collator_compare() function in PHP: Program 1: php <?php // Declare variable and initialize it $str1 = 'Geeks'; $str2 = 'geeks'; $coll = collator_create( 'en_US' ); // Compare both strings $res = collator_compare( $coll, $str1, $str2 ); if ($res === false) echo collator_get_error_message( $coll ); else if( $res > 0 ) echo $str1 . " is greater than " . $str2 . "\n"; else if( $res < 0 ) echo $str1 . " is less than " . $str2 . "\n"; else echo $str1 . " is equal to " . $str2; ?> Output: Geeks is greater than geeks Program 2: php <?php // Declare the variable and initialize it $str1 = 'GeeksforGeeks'; $str2 = 'GeeksforGeeks'; $coll = collator_create( 'en_US' ); // Compare both strings $res = collator_compare( $coll, $str1, $str2 ); if ($res === false) echo collator_get_error_message( $coll ); else if( $res > 0 ) echo $str1 . " is greater than " . $str2 . "\n"; else if( $res < 0 ) echo $str1 . " is less than " . $str2 . "\n"; else echo $str1 . " is equal to " . $str2; ?> Output: GeeksforGeeks is equal to GeeksforGeeks Reference: http://php.net/manual/en/collator.compare.php Comment More infoAdvertise with us Next Article PHP | collator_compare() Function V vijay_raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | Collator create() Function The Collator::create() function is an inbuilt function in PHP which is used to create a new collector. Syntax: Object oriented style: Collator Collator::create( $locale ) Procedural style: Collator collator_create( $locale ) Parameters: This function accepts single parameter $locale which holds the 1 min read 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 1 min read 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: Procedural style: bool collator_sort( $coll, $arr, $sort_flag ) Object oriented style: bool Collator::sort( $arr, $so 2 min read PHP | collator_asort() Function The collator_asort() function is an inbuilt function in PHP which is used to sort array maintaining the index association. This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. The array elements are sorted according to curr 2 min read PHP | bccomp() Function The bccomp() function in PHP is an inbuilt function and is used to compare two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the result of comparison of the two numbers after comparing them upto a specified precision. Syntax: int bccomp ( $ 3 min read Like