You are here : phpstringstrnatcmp

strnatcmp() - string

This function implements a comparison algorithm that orders
   alphanumeric strings in the way a human being would, this is
   described as a "natural ordering".  
   Note that this comparison is case sensitive.
Parameters :
  • str1 - The first string.
  • str2 - The second string.

  • Syntax

    int strnatcmp
        ( string $str1
       , string $str2
       )


    Example

    <?php$arr1 = $arr2 = array("img12.png", "img10.png", "img2.png", "img1.png");echo "Standard string comparison\n";usort($arr1, "strcmp");print_r($arr1);echo "\nNatural order string comparison\n";usort($arr2, "strnatcmp");print_r($arr2);?>


    Output / Return Value


    Limitations


    Alternatives / See Also


    Reference