String comparison function; comparison function; string comparison

php strnatcasecmp() function syntax

Function:Use the "natural" algorithm to compare two strings (not case-sensitive):

Syntax:strnatcasecmp(string1,string2)

Parameters:

Parameters Description
string1 Required, specifies the first string to be compared.
string2 Required, specifies the second string to be compared.

Description: Thestrnatcasecmp() function uses a "natural" algorithm to compare two strings. In natural arithmetic, the number 2 is less than the number 10. In computer sorting, 10 is less than 2 because the first number in 10 is less than 2. strnatcasecmp() is not case sensitive. If the two strings are equal, 0 is returned. If string1 is greater than string2, the returned value is greater than 0. If string1 is less than string2, the returned value is less than 0

php strnatcasecmp() function example

"; echo strnatcasecmp("01hello world!","2hello world!"); ?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

1 -1