Hướng dẫn
Quảng cáo

Hàm strcoll() trong PHP

Hướng dẫn cách sử dụng hàm strcoll() trong lập trình PHP

Tác dụng của hàm strcoll()

The strcoll() function compares two strings.

This function uses the current locale for doing the comparisons. If the current locale is set to C or POSIX, this function is equivalent to strcmp() function.

The following table summarizes the technical details of this function.

Return Value: Returns a negative value (< 0) if string1 is less than string2; a positive value (> 0) if string1 is greater than string2, and 0 if both strings are equal.
Version: PHP 4+

Tip: A locale is an identifier that determines the language of the user interface as well as how information such as numbers, currencies, dates and times are formatted.


Syntax

The basic syntax of the strcoll() function is given with:

strcoll(string1, string2);

The following example shows the strcoll() function in action.

<?php
// Sample strings
$str1 = "alligator";
$str2 = "Alligator";

// Setting locale to C and compare
setlocale(LC_ALL, "C");
echo strcoll($str1, $str2)."<br>";

// Setting locale to US and compare
setlocale(LC_ALL, "en_US.UTF-8");
echo strcoll($str1, $str2);
?>

Parameters

The strcoll() function accepts the following parameters.

Parameter Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.

Bài viết này đã giúp ích cho bạn?

Bài viết mới

Advertisements