我制作了这个虚构的会员名单。我想保持子数组(类年)的顺序,同时按每个子数组内的降序键排序。
$pledges = array(
'smith' => "Joe Patterson",
'jones' => "Robert Nelson",
'davis' => "Jimmy Davis",
'carpenter' => "Mike Carpenter");
$sophomores = array(
'ford' => "Kevin Ford",
'gomez' => "Pedro Gomez",
'miller' => "Jack Miller",
'pullman' => "Lucas Pullman");
$juniors = array(
'bradford' => "Nicholas Bradford",
'daniels' => "Robert Daniels",
'soren' => "Jon Soren",
'cooper' => "Harrison Cooper");
$seniors = array(
'mcdonald' => "Casey McDonald",
'witten' => "Tim Witten",
'session' => "Benjamin Sessions",
'redding' => "Jack Redding");
我该怎么做?谢谢。
PHP手册中有一个很好的例子。
http://www.php.net/manual/en/function.ksort.php 98465
使用PHP的ksort函数可以对数组键进行排序。
ksort($pledges);
array_reverse($pledges);
and like wise for others....
你发布的是单维度数组,请注意ksort将只适用于单维度数组。