BHP offers different methods of sorting the elements in an array.
We'll start with this sort.
Function in this example we have an array called names with eight values.
John Bob Dana Sue and so on to sort each value in the array alphabetically we can use this sort function
to do so we type sort in the name of beery in parenthesis
next.
We can use a for loop to output each value in the array.
You can see the output in our web browser and each value is sorted alphabetically.
Note that this sort function works for numerical values as well.
And we can use the r sort function to reverse sort their values to simply replace sort with our sort
save the file and refresh.
And now you can see it's the order has been reverse
we can sort the elements in an Associated very in ascending order by their value using the a sort function
so here we have an associate of array named T score inside this array we have three keys and three values.
John Bill and Dan being the keys and the values being 60 80 and 75.
To sort them in ascending order type a sort.
And then the name of the array in parentheses
next use a for each group to output each element in the red and you can see in your in our web browser
that we've sorted it by the value and not the key we can sort by key rather than value by using the
case or function and now we've sorted by Keith
to sort according to value in descending order use a r sort.
So again this is the sort reporting to value in descending order.
Now we have eighty seventy five and sixty to sort according to key in descending order use k are sorted
and now you can see we have John then and Bill.