How to use strnatcmp in PHP
In this article I will explain how strnatcmp function used in PHP.
strnatcmp() Function
This function compares two strings and it used natural algorithm.
and returns:
- 0 - if the two strings are equal
- <0 - if string1 is less than string2
- >0 - if string1 is greater than string2
In this algorithm, 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.
Note- It is a case-sensitive.
Syntax
strnatcmp(string1,string2) |
Parameter |
Description |
string1 |
first string to compare |
string2 |
second string to compare |
Example
<html>
<body>
<?php
echo strnatcmp("2Hello Rajnikant!","10Hello Sharukh!");
echo "<br />";
echo strnatcmp("10swati sharma","2sachin bhardwaj");
?>
</body>
</html> |
Output
You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here