PHP strnatcasecmp() Function (original) (raw)

Last Updated : 22 Jun, 2023

The strnatcasecmp() function is a built-in function in PHP which compares this string using "natural order" algorithm. This function accepts two strings as parameter and returns an integer value (positive, negative or zero ). This function is similar to strnatcmp() with the only difference being the case-insensitivity of the function.Syntax:

strnatcasecmp( string1,string1, string1,string2 )

Parameters: The function accepts two mandatory string parameters as shown in the above syntax. These parameters are defined below :

Return Values: This function returns a positive integer, negative or 0 based on the below conditions:

Examples:

Input : string="Geek",string = "Geek", string="Geek",string2 = "GEEK" Output : 0

Input : string="Geeks",string = "Geeks", string="Geeks",string2 = "Geek" Output : 1

Below programs illustrate the strnatcasecmp() function:Program 1: This program illustrates simple use of the strnatcasecmp() function.

php `

`

Output

1

Program 2: This program illustrates case-insensitivity of the strnatcasecmp() function.

php `

`

Output

0 1