Muck A. Round Posted July 4, 2021 Share Posted July 4, 2021 (edited) I feel like I'm missing something on the example for Sort Array (Ascending Order), According to Value - asort(). I added a var_dump and also switched the variables to ABC, and don't see that any sorting is occurring. <!DOCTYPE html> <html> <body> <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); asort($age); var_dump($age); echo "<br><br>"; foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } echo "<br>"; $age = array("C"=>"35", "B"=>"37", "A"=>"43"); asort($age); var_dump($age); echo "<br>"; echo "<br>"; foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?> </body> </html> Edited July 4, 2021 by Muck A. Round changed quotes to bold face Link to comment Share on other sites More sharing options...
Ingolme Posted July 4, 2021 Share Posted July 4, 2021 Your initial array is already sorted. Try changing the numbers to be out of order. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 4, 2021 Share Posted July 4, 2021 Are you confusing key sort (ksort with C,B,A), with value sort (asort 35,37,43)?. Link to comment Share on other sites More sharing options...
Muck A. Round Posted July 5, 2021 Author Share Posted July 5, 2021 Ah - thanks everyone. What I was missing was that an associative array is defined as KEY => VALUE. So when you say "value" you're not talking about the value (or amount?) of any given entry, but value as the entity that each key is associated with. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now