返回按字母顺序或按数字升序排序的数组。返回的数组与原始数组具有相同数量和类型的元素。
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"); }
sort 函数会按升序对 $myInts 的元素进行排序。在“脚本编辑器”(Script Editor)中会显示以下内容:
After sorting, the array contains: 1 2 3 4 5 6
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"); }
sort 函数会按字母顺序对 $myName 的元素进行排序。在“脚本编辑器”(Script Editor)中会显示以下内容:
After sorting, the array contains: Kennedy Michael Peewee