php數(shù)組排序后如何輸出

PHP
小億
84
2024-02-27 11:55:55

在PHP中,您可以使用sort()函數(shù)對(duì)數(shù)組進(jìn)行排序,然后使用循環(huán)遍歷數(shù)組來(lái)輸出排序后的結(jié)果。以下是一個(gè)簡(jiǎn)單的示例:

$fruits = array("apple", "banana", "orange", "grape", "cherry");

sort($fruits);

foreach ($fruits as $fruit) {
    echo $fruit . "<br>";
}

運(yùn)行上面的代碼將輸出以下結(jié)果:

apple
banana
cherry
grape
orange

0