strnatcmp

(PHP 4, PHP 5, PHP 7)

strnatcmp使锟斤拷锟斤拷然锟斤拷锟斤拷锟姐法锟饺斤拷锟街凤拷锟斤拷

说锟斤拷

strnatcmp ( string $str1 , string $str2 ) : int

锟矫猴拷锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷习锟竭讹拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷谋冉锟斤拷惴拷锟斤拷锟斤拷锟斤拷"锟斤拷然顺锟斤拷"锟斤拷注锟斤拷帽冉锟斤拷锟斤拷执锟叫⌒达拷锟�

锟斤拷锟斤拷

str1

锟斤拷一锟斤拷锟街凤拷锟斤拷锟斤拷

str2

锟节讹拷锟斤拷锟街凤拷锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟饺较猴拷锟斤拷锟斤拷锟狡o拷锟斤拷锟� str1 小锟斤拷 str2 锟斤拷锟斤拷 < 0锟斤拷 锟斤拷锟� str1 锟斤拷锟斤拷 str2 锟斤拷锟斤拷 > 0锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟饺o拷锟斤拷锟斤拷 0锟斤拷

锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷锟斤拷锟秸故撅拷烁锟斤拷惴拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷冉锟斤拷惴拷锟� strcmp() 锟斤拷使锟矫的o拷锟斤拷锟斤拷锟斤拷

<?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);
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

Standard string comparison
Array
(
    [0] => img1.png
    [1] => img10.png
    [2] => img12.png
    [3] => img2.png
)

Natural order string comparison
Array
(
    [0] => img1.png
    [1] => img2.png
    [2] => img10.png
    [3] => img12.png
)
锟斤拷锟斤拷锟斤拷息锟斤拷锟轿硷拷锟斤拷Martin Pool 锟斤拷» 锟斤拷然顺锟斤拷锟斤拷址锟斤拷锟斤拷冉锟� page.

锟轿硷拷

  • preg_match() - 执锟斤拷匹锟斤拷锟斤拷锟斤拷锟斤拷式
  • strcasecmp() - 锟斤拷锟斤拷锟狡帮拷全锟饺斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街达拷小写锟斤拷
  • substr() - 锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟接达拷
  • stristr() - strstr 锟斤拷锟斤拷锟侥猴拷锟皆达拷小写锟芥本
  • strcmp() - 锟斤拷锟斤拷锟狡帮拷全锟街凤拷锟斤拷锟饺斤拷
  • strncmp() - 锟斤拷锟斤拷锟狡帮拷全锟饺斤拷锟街凤拷锟斤拷锟斤拷头锟斤拷锟斤拷锟缴革拷锟街凤拷
  • strncasecmp() - 锟斤拷锟斤拷锟狡帮拷全锟饺斤拷锟街凤拷锟斤拷锟斤拷头锟斤拷锟斤拷锟缴革拷锟街凤拷锟斤拷锟斤拷锟斤拷锟街达拷小写锟斤拷
  • strnatcasecmp() - 使锟斤拷“锟斤拷然顺锟斤拷”锟姐法锟饺斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街达拷小写锟斤拷
  • strstr() - 锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟阶次筹拷锟斤拷
  • natsort() - 锟斤拷“锟斤拷然锟斤拷锟斤拷”锟姐法锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • natcasesort() - 锟斤拷“锟斤拷然锟斤拷锟斤拷”锟姐法锟斤拷锟斤拷锟斤拷锟斤拷胁锟斤拷锟斤拷执锟叫⌒达拷锟侥革拷锟斤拷锟斤拷锟�