scripting@wanadoo.nl




Asort()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
9 January 2002 Asort()
AuthorScriptLogic Corporation
Action Sorts the elements of the array.
SyntaxAsort (array, [sort]) 
Parameters
  • array (Required / Array) the array which you want to sort.
  • sort (Optional / Numeric) the order in which to sort the array. If sort = 0 (or is omitted), the array will be sorted in ascending order. If sort = 1, the array will be sorted in descending order. 
  • RemarksDon't have a use for this yet, but still a neat UDF example... 
    ReturnsAn array sorted in the order requested. 
    DependenciesNone. 
    Examples
    $array='carl','frank','aaron','robert','ulysses','brad'
    ?'Starting with:'
    for each $element in $array
      ?$element
    next
    
    $sortedarray=Asort($array)
    ?'Here are ascending results:'
    for each $element in $sortedarray
      ?$element
    next
    
    $sortedarray=Asort($array,1)
    ?'Here are descending results:'
    for each $element in $sortedarray
      ?$element
    next
    
     
    Source
    FUNCTION Asort ($array, OPTIONAL $order)
      ; sort order: 0 = ascending, 1 = decending
      DIM $index, $x, $y, $tmp, $changed
      $asort=$array
      $order=0+$order
      DO
        $changed=0
        FOR $index = 0 TO UBound($asort)-1
          $x=$asort[$index]
          $y=$asort[$index+1]
          IF ($x > $y AND 1-$order) OR ($x < $y AND $order)
            $tmp=$x
            $asort[$index]=$y
            $asort[$index+1]=$tmp
            $changed=1
          ENDIF
        NEXT
      UNTIL $changed=0
    ENDFUNCTION ; - Asort -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter