64
PHP strnatcmp() Function
The strnatcmp() function in-built string function of PHP. It is used to compare string by using a natural algorithm.
Syntax:
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
Output:
By Using strnatcmp()Function:-1
Example 2
Output:
By Using strnatcmp()Function:1
Example 3
Output:
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.
Reference:
http://php.net/manual/en/function.strncmp.php
Next TopicPHP String