-3

It is array:

$a = rand(1,100);
$b = rand(1,100);
$c = rand(1,100);
$arr =  array($a ,$b , $c);

I want to sort generated numbers high to low.

halfer
  • 19,824
  • 17
  • 99
  • 186
Норайр
  • 11
  • 1
  • 2

4 Answers4

2

Sort Array (Descending Order), According to Value - arsort()

<!DOCTYPE html>
<html>
<body>

<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
arsort($age);

foreach($age as $x => $x_value) {
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "<br>";
}
?>

</body>
</html>

Output:

Key=Joe, Value=43
Key=Ben, Value=37
Key=Peter, Value=35
halfer
  • 19,824
  • 17
  • 99
  • 186
Naresh Kumar P
  • 4,127
  • 2
  • 16
  • 33
1

It's simple:

rsort($arr);

PHP manual page

Blazeag
  • 481
  • 8
  • 13
0

Use arsort(): reference

    print_r(arsort($arr));

Sort an associative array in descending order, according to the value:

JYoThI
  • 11,977
  • 1
  • 11
  • 26
0
Use 
$sort = arsort($arr);
print_r()
Rana Aalamgeer
  • 702
  • 2
  • 8
  • 22