To sort this array, you just use the assort( ) function. This involves nothing more complex than typing the word asort, followed by round brackets. In between the round brackets, type in the name of your Associative array:

asort( $full_name );

The letter “a” tells PHP that the array is an Associative one. (If you don’t have the “a” before “sort”, your key names will turn in to numbers!). The “a” also tells PHP to sort by the Value, and NOT by the key. In our script above, the surnames will be sorted. If you want to sort using the Key, then you can use ksort() instead.

If you have a Scalar array (numbers as Keys), then you leave the “a” off. Like this: