php sort array remove keys
"lemon", "a" => "orange", "b" => "banana", "c" => "apple"); asort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } ?> //Would output: c = apple b = banana d = lemon a = orange
Here is what the above code is Doing:
1. First, we create an array of fruits.
2. Then, we sort the array by value, using the asort() function.
3. Finally, we loop through the array, and print out the key and value of each element.
The output of the above code would be:
c = apple
b = banana
d = lemon
a = orange
Notice that the keys are preserved, but the values are sorted.