Definition
The strnatcmp() function compares(case-sensitive) two strings using a "natural" algorithm.
Syntax
strnatcmp(string1, string2)
Parameters
Parameter | Description |
---|---|
string1 |
Required. Specifies the first string to compare. |
string2 |
Required. Specifies the second string to compare. |
Example
<?php
// Example 1
echo strnatcmp("2PHP", "10php");
echo "<br>";
// Example 2
$arr = array("DSC1", "dsc2", "DSC10", "DSC01", "dsc100", "dsc20", "DSC30", "dsc200");
usort($arr, "strnatcmp");
print_r($arr);