In PHP, an associative array is an array with string keys rather than numeric keys. You can sort an associative array by value using the asort() function. This function sorts the values of the array in ascending order while maintaining the association between the keys and values.
Here is an example of how to use asort() to sort an associative array by value:
The output of this code will be:
You can also use the arsort() function to sort the values of an associative array in descending order.
The output of this code will be:
It's important to note that the asort() and arsort() functions modify the original array, so you don't need to assign the sorted array to a new variable.