Javatpoint Logo
Javatpoint Logo

PHP strnatcmp() Function

The strnatcmp() function in-built string function of PHP. It is used to compare string by using a natural algorithm.


Parameter Description Required/Optional
string1 required
string2 required

This function strnatcmp():

  • returns: <0 if str1 is less than str2;
  • returns : >0 if str1 is greater than str2;
  • returns: 0 if they are equal.

Note: It is case sensitive.

Example 1


By Using strnatcmp()Function:-1

Example 2


By Using strnatcmp()Function:1

Example 3


Standard string comparisonnArray 
[0] => PHP1 
[1] => PHP10 
[2] => PHP12 
[3] => PHP2 
nNatural order string comparisonnArray 
   [0] => PHP1 
   [1] => PHP2  
   [2] => PHP10 
   [3] => PHP12 	

See Also:

  • str_pad() : It is used to pad a string to a new length.
  • str_ireplace() : It is used to replace some characters in a string (case-insensitive).
  • str_repeat() : It is used to repeat a string a specified number of times.


Next TopicPHP String

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA