PHP asort() 函数 按照键值对关联数组进行升序排序

PHP - 数组的排序函数

在本节中,我们将学习如下 PHP 数组排序函数:

  • sort() - 以升序对数组排序
  • rsort() - 以降序对数组排序
  • asort() - 根据值,以升序对关联数组进行排序
  • ksort() - 根据键,以升序对关联数组进行排序
  • arsort() - 根据值,以降序对关联数组进行排序
  • krsort() - 根据键,以降序对关联数组进行排序

PHP asort() 函数

实例

按照键值对关联数组进行升序排序:

<?php
header("Content-type: text/html; charset=utf-8");
$age=array(60 => "Bill",56 => "Steve",31 => "Mark");
asort($age);
var_dump($age);
?>
array (size=3)
  60 => string 'Bill' (length=4)
  31 => string 'Mark' (length=4)
  56 => string 'Steve' (length=5)

 

posted @ 2018-01-10 17:35  sky20080101  阅读(313)  评论(0)    收藏  举报