How can I reverse sort an array keeping the correlation
between the index and value?

Answer Posted / amit

<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" =>
"banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>

OUTPUT

a = orange
d = lemon
b = banana
c = apple

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to randomly retrieve a value from an array?

726


What is framework in php?

699


What is repository in php?

712


How to pass variables and data from php to javascript?

686


What are the array functions in php?

698


How long is csrf token?

688


Does mysql need php?

669


Write a program to find a string is palindrome or not?

692


What are the advantages of oops in php?

720


How to assigning a new character in a string?

745


Explain what are psrs?

674


Is php required for wordpress?

697


Can I include php in javascript?

788


Tools used for drawing er diagrams?

726


What is $_ get and $_ post in php?

677