Home > Backend Development > PHP Tutorial > Introduction to the characteristics of PHP natural language sorting_PHP tutorial

Introduction to the characteristics of PHP natural language sorting_PHP tutorial

WBOY
Release: 2016-07-15 13:29:46
Original
1461 people have browsed it

We use Listing G as an example of PHP natural language sorting:

<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 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 class=""><SPAN>natsort($data); print_r($data);</SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li></ol>
Copy after login

Its output is as follows:

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

)

Their difference is already clear: the second sorting result It is more intuitive and "human", while the first one is more in line with the rules of the algorithm and has more "computer" characteristics. This is PHP natural language sorting.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446349.htmlTechArticleWe use Listing G as an example of PHP natural language sorting: ? php $ data = array ("book- 1","book-10","book-100", "book-5");sort($data);print_r($data); natsort($data);pri...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template