The asort() function accepts an associative array and sorts its values either alphabetically if any strings are present or numerically if all elements are numbers. However, the asort() function preserves the array keys. Consider the following example: