PHP strnatcasecmp() ပုံစံ

အကျိုးသတ္တု

နှစ်ခုပေါင်း သော စကားလုံး ကို "ပုံစံ" ပေါ်မူရာ ကြောင်း နှင့် နှိုင်းယှဉ်သည် (အရွယ်အစား မမှန်းချက် မပြုဘဲ):

<?php
echo strnatcasecmp("2Hello world!","10Hello WORLD!");
echo "<br>";
echo strnatcasecmp("10Hello world!","2Hello WORLD!");
?>

အခြေခံ အမှတ်အသား

အသုံးပြုခြင်း နှင့် အသုံးချက်

strnatcasecmp() ပုံစံ ကို နှစ်ခုပေါင်း သော စကားလုံး ကို "ပုံစံ" ပေါ်မူရာ ကြောင်း နှင့် နှိုင်းယှဉ်သည်။

In natural algorithms, number 2 is less than number 10. In computer sorting, 10 is less than 2, because the first digit in 10 is less than 2.

Note:strnatcasecmp() is case-insensitive.

Syntax

strnatcasecmp(string1,string2)
Parameters Description
string1 Required. Specify the first string to be compared.
string2 Required. Specify the second string to be compared.

Technical details

Return value:

This function returns:

  • 0 - If two strings are equal
  • <0 - If string1 is less than string2
  • >0 - If string1 is greater than string2
PHP version: 4+

More examples

Example 1

Natural algorithm (strnatcmp) and standard computer string sorting algorithm (strcmp) difference:

<?php
$arr1 = $arr2 = array("pic1","pic2","pic10","pic01","pic100","pic20","pic30","pic200");
echo "Standard string comparison"."<br>";
usort($arr1,"strcmp");
print_r($arr1);
echo "<br>";
echo "Natural order string comparison"."<br>";
usort($arr2,"strnatcmp");
print_r($arr2);
?>

အခြေခံ အမှတ်အသား