<p>Values <?php echo $_POST['submitted'] ? "sorted by {$sortType}" : "unsorted";
?>:</p>
<ul>
<?php foreach ($values as $key => $value) {
echo "<li><b>{$key}</b>: {$value}</li>";
} ?>
</ul>
</form>
按自然顺序排序
PHP
的内置排序函数可以正确排序字符串和数组,但是不能对含有数字的字符串进行正
确排序。例如,如果有文件名:
ex10.php
、
ex5.php
和
ex1.php
。一般的排序函数会把它
们按这样排序:
ex1.php
、
ex10.php
、
ex5.php
。要对含有数字的字符串正确排序,应使用
natsort()
和
natcasesort()
函数:
$output = natsort(input);
$output = natcasesort(input);
一次对多个数组进行排序
array_multisort()
函数可以一次对多个索引数组进行排序:
array_multisort(
array1
[,
array2
, ... ]);
函数接收一系列数组并排序(通过
SORT_ASC
或
SORT_DESC
常量确定),函数对所有数组
的元素进行重新排序并分配新的索引。这类似关系数据库中的关联( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.