php在不去重的情況下對(duì)數(shù)組排序的方法:【$cars=array("porsche","BMW","Volvo");sort($cars);】,表示按照字母升序?qū)?shù)組中的元素進(jìn)行排序。
函數(shù)介紹:
sort() – 以升序?qū)?shù)組排序
rsort() – 以降序?qū)?shù)組排序
(推薦教程:php視頻教程)
舉例:
按照字母升序?qū)?shù)組 $cars 中的元素進(jìn)行排序
代碼實(shí)現(xiàn):
<?php $cars=array("porsche","BMW","Volvo"); sort($cars); ?>
按照數(shù)字升序?qū)?shù)組 $numbers 中的元素進(jìn)行排序
代碼實(shí)現(xiàn):
<?php $numbers=array(3,5,1,22,11); sort($numbers); ?>
按照字母降序?qū)?shù)組 $cars 中的元素進(jìn)行排序
<?php $cars=array("porsche","BMW","Volvo"); rsort($cars); ?>
按照數(shù)字降序?qū)?shù)組 $numbers 中的元素進(jìn)行排序
<?php $numbers=array(3,5,1,22,11); rsort($numbers); ?>