[php] asort — 對陣列進行排序並保持索引關係

官方範例
Example #1 asort() 例子
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>

以上例程會輸出:

c = apple
b = banana
d = lemon
a = orange

其它範例:

<?php
$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

asort($my_array);
print_r($my_array);
?>

輸出:

Array
(
[b] => Cat
[a] => Dog
[c] => Horse
)



arrow
arrow
    全站熱搜
    創作者介紹
    創作者 stockwfj3 的頭像
    stockwfj3

    程式設計@筆記

    stockwfj3 發表在 痞客邦 留言(0) 人氣()