我们通过对Listing G就是一个PHP自然语言排序的例子:
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">data</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>("book-1", "book-10", "book-100", <br>"book-5"); sort($data);print_r($data); </span></span></li> <li class=""> <span>natsort($data); print_r($data);</span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
它的输出结果如下:
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自然语言排序。