萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php 數組排序 array_multisort rsort krsort

php 數組排序 array_multisort rsort krsort

這裡主要是rsort krsort函數,他是對鍵名進行反序排序了,如果要數組元素值排序用sort就成了,array_multisort這個是對多維數組排序。
*/
$array = array(array('www.111cn.net',6,8),array(1,2,6));
print_r($array);
/*
array
(
    [0] => array
        (
            [0] => www.111cn.net
            [1] => 6
            [2] => 8
        )

    [1] => array
        (
            [0] => 1
            [1] => 2
            [2] => 6
        )

)
*/
array_multisort($array) ;//對二維數組進行排序
print_r($array);
/*
array
(
    [0] => array
        (
            [0] => www.111cn.net
            [1] => 6
            [2] => 8
        )

    [1] => array
        (
            [0] => 1
            [1] => 2
            [2] => 6
        )

)
*/

$ar = array('111cn.net',2,3,5);
rsort($ar);
print_r($ar);
/*
array
(
    [0] => 5
    [1] => 3
    [2] => 2
    [3] => 111cn.net
)
*/

krsort($ar);
print_r($ar);
/*
array
(
    [3] => 111cn.net
    [2] => 2
    [1] => 3
    [0] => 5
)*/

copyright © 萬盛學電腦網 all rights reserved