Sort an array in reverse order and maintain index association : Array sort « Data Structure « PHP
- PHP
- Data Structure
- Array sort
Sort an array in reverse order and maintain index association
<?
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
arsort ($fruits);
for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
echo "fruits[$key] = ".$fruits[$key]."\n";
}
?>
Related examples in the same category