Easy Tutorial
❮ Func Curl_Strerror Func Misc Connection Aborted ❯

PHP strnatcmp() Function

PHP String Reference Manual

Example

Compare two strings using a "natural" algorithm (case-sensitive):


Definition and Usage

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

In natural algorithms, 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: This function is case-sensitive.


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 Curl_Strerror Func Misc Connection Aborted ❯