Home  >  Article  >  php教程  >  PHP自然语言排序的特点介绍

PHP自然语言排序的特点介绍

WBOY
WBOYOriginal
2016-06-13 11:06:451436browse

我们通过对Listing G就是一个PHP自然语言排序的例子:

  1. php 
  2. $data = array("book-1", "book-10", "book-100", 
    "book-5"); sort($data);print_r($data);  
  3. natsort($data); print_r($data);?> 

它的输出结果如下:

Array ([0] => book-1

[1] => book-10

[2] => book-100

[3] => book-5

)

Array

(

[0] => book-1

[3] => book-5

[1] => book-10

[2] => book-100

)

它们的不同已经很清楚了:第二个排序结果更直观,更“人性化”,然而第一个则更符合算法规则,更具“计算机”特点。这就是PHP自然语言排序。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn