To sort an associative array by its keys in PHP, you use the ksort() function or the krsort() function for ______ order.

  • Ascending
  • Descending
  • Random
  • Unspecified
To sort an associative array by its keys in PHP, you use the ksort() function. The ksort() function arranges the elements of an associative array in ascending order based on their keys. It directly modifies the original associative array by rearranging its key-value pairs. If you need to sort the associative array in descending order based on the keys, you would use the krsort() function instead. Sorting associative arrays by keys is useful when you want to organize and retrieve data based on a specific key order. Learn more: https://www.php.net/manual/en/function.ksort.php, https://www.php.net/manual/en/function.krsort.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *