Javatpoint Logo
Javatpoint Logo

PHP strnatcasecmp() Function

The strnatcasecmp() function is in-built function of PHP. It is used to compare two strings using a "natural order" algorithm. This function accepts two string as parameter and return integer value. It is similar to strnatcmp() function.

Note: This function strnatcasecmp() is case-insensitive.

Syntax:


Parameter Description Required/Optional
String1 Specify the first string to compare. Required.
String2 Specify the second string to compare.
It returns :
  • 0 : if the two strings are equal
  • <0 : if string1 is less than string2
  • >0 :I f string1 is greater than string2
Required.

Example 1

Output:

Your string is: Hello world! Hello world!
By using 'strnatcasecmp()' function: 0

Example 2

Output:

Your string is: 2Hello world!10Hello WORLD!
By using 'strnatcasecmp()' function: -1

Example 3

Output:

Your string is: 10Hello world!2Hello WORLD!
By using 'strnatcasecmp()' function: 1

See Also

  • trim() : It is used to remove whitespace.
  • ltrim() : It is used to remove whitespace from the left side of a string.
  • rtrim() : It is used to remove whitespace from the right side of a string.

Reference:

http://php.net/manual/en/function.strnatcasecmp.php







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA