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>
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.