Friday, August 28, 2015

array in descending order in php

<?php
$array = [2, 5, 7, 99, 90, 42, 88, 8, 9, 0, 56];
$count = count($array);
for($i = 0; $i < $count; $i++){
    for($j = 0; $j < $count-1; $j++){
        if($array[$j] < $array[$j+1]){
           $temp = $array[$j+1];
            $array[$j+1]= $array[$j];
            $array[$j] = $temp;
        }
    }
}

for($k = 0; $k < $count; $k++){
    echo $array[$k] . '<br>';
}

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }