📜  手动对 php 中的数组进行排序 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:41.780000             🧑  作者: Mango

代码示例1
// take an array with some elements
$array = array('a','z','c','b');
// get the size of array
$count = count($array);
echo "
";
// Print array elements before sorting
print_r($array);
for ($i = 0; $i < $count; $i++) {
    for ($j = $i + 1; $j < $count; $j++) {
        if ($array[$i] > $array[$j]) {
            $temp = $array[$i];
            $array[$i] = $array[$j];
            $array[$j] = $temp;
        }
    }
}
echo "Sorted Array:" . "
"; print_r($array);