php Natsort的例子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Natsort的例子相关的知识,希望对你有一定的参考价值。
<span style="color: #808080; font-style: italic;">// create a example array</span>
<span style="color: #0000ff;">$array_1</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'pic10.jpg'</span>, <span style="color: #ff0000;">'pic3.jpg'</span>, <span style="color: #ff0000;">'pic1.jpg'</span>,
<span style="color: #ff0000;">'pic7.jpg'</span>, <span style="color: #ff0000;">'pic99.jpg'</span>, <span style="color: #ff0000;">'pic127.jpg'</span>
<span style="color: #66cc66;">)</span>;
<span style="color: #808080; font-style: italic;">// copy array 1</span>
<span style="color: #0000ff;">$array_2</span> = <span style="color: #0000ff;">$array_1</span>;
<a href="http://www.php.net/sort"><span style="color: #000066;">sort</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$array_1</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">"Standard sorting algorithm:<br/><span style="color: #000099; font-weight: bold;">\n</span>"</span>;
<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$array_1</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>"</span>;
<a href="http://www.php.net/natsort"><span style="color: #000066;">natsort</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$array_2</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">"Natural order sorting:<br/><span style="color: #000099; font-weight: bold;">\n</span>"</span>;
<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$array_2</span><span style="color: #66cc66;">)</span>;
<span style="color: #808080; font-style: italic;">/*
Output:
Standard sorting algorithm
Array
(
[0] => pic1.jpg
[1] => pic10.jpg
[2] => pic127.jpg
[3] => pic3.jpg
[4] => pic7.jpg
[5] => pic99.jpg
)
Natural order sorting
Array
(
[2] => pic1.jpg
[1] => pic3.jpg
[3] => pic7.jpg
[0] => pic10.jpg
[4] => pic99.jpg
[5] => pic127.jpg
)
*/</span>
以上是关于php Natsort的例子的主要内容,如果未能解决你的问题,请参考以下文章