Easy Tutorial
❮ Func Misc Highlight String Func Cal Jdtojulian ❯

PHP strnatcasecmp() Function

PHP String Reference Manual

Example

Using the "natural" algorithm to compare two strings (case-insensitive):


Definition and Usage

The strnatcasecmp() function uses a "natural" algorithm to compare two strings (case-insensitive).

In natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first digit of 10 is less than 2.

Note: strnatcasecmp() is case-insensitive.


Syntax

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

Technical Details

Return Value: The function returns: 0 - if the two strings are equal<br> <0 - if string1 is less than string2<br> >0 - if string1 is greater than string2
PHP Version: 4+
--- ---

More Examples

Example 1

Differences between the natural algorithm (strnatcmp) and the regular computer string sorting algorithm (strcmp):


❮ Func Misc Highlight String Func Cal Jdtojulian ❯