Why does this code not display in alphabetical order?

plz format your code in proper manner for html and remove the extra spaces. you can use sort($terms); to
arrange values in alphabetical order.