sort
 
 
 

Returns an array sorted in alphabetical or ascending numerical order. The returned array has the same number and type of elements as the original array.

array sort(array array)

array is the name of the array to be sorted.

Example 1

int $myInts[] = {3,6,1,4,2,5};
int $afterSorting[] = sort($myInts);
print("After sorting, the array contains:\n");
for ($i = 0; $i < 6; $i = $i + 1)
	{
	print($afterSorting[$i]+"\n");
	}

The sort function sorts the elements of $myInts in ascending order. The following appears in the Script Editor:

After sorting, the array contains:
1
2
3
4
5
6

Example 2

string $myName[] = {"Peewee","Michael","Kennedy"};
string $afterSorting[] = sort($myName);
print("After sorting, the array contains:\n");
for ($i = 0; $i < 3; $i = $i + 1)
	{
	print($afterSorting[$i]+"\n");
	}

The sort function sorts the elements of $myName in alphabetical order. The following appears in the Script Editor:

After sorting, the array contains:
Kennedy
Michael
Peewee