This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Arrays

Sort Array (Descending Order), According to Key - krsort()

Key=Peter, Value=35
Key=Joe, Value=43
Key=Ben, Value=37

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

// sort the array descending key order
krsort($age);

// display the array in the new order
foreach($age as $x => $x_value) {
  echo "Key=" . $x . ", Value=" . $x_value;
  echo "<br>";
}
?>