Lasso Soft Inc. > Home

[ array->sort ]

Method

The [array->sort] method reorders the elements of the array in alphabetical or numerical order. Accepts a single boolean parameter. Sorts in ascending order by default or if the parameter is True and in descending order if the parameter is False. Optionally the keywords -descending or -ascending may be used instead of false and true respectively.

Note: Only string, integer, or decimal values should be sorted. If an array contains arrays or maps then the results of sorting the array are undetermined. Pairs will be sorted by their first element (which should be either a string, integer, or decimal value).

  • Syntax
array->sort( sort_order )
Examples
  • Beginner

To sort the elements in an array:

Use the [array->sort] method. The following examples sorts the items in an array of the days of the week in various ways and outputs the sorted array.

Code

var( DaysOfWeek = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') )

$DaysOfWeek->sort(true)
'Sorted Ascending: '+$DaysOfWeek+'\n'

$DaysOfWeek->sort(-descending)
'Sorted Descending: '+$DaysOfWeek+'\n'

Result

Sorted Ascending: array(Fri, Mon, Sat, Sun, Thu, Tue, Wed)
Sorted Descending: array(Wed, Tue, Thu, Sun, Sat, Mon, Fri)

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft