|
|
|
| 9 January 2002 | Asort() |
| Author | ScriptLogic Corporation |
| Action | Sorts the elements of the array. |
| Syntax | Asort (array, [sort]) |
| Parameters | |
| Remarks | Don't have a use for this yet, but still a neat UDF example... |
| Returns | An array sorted in the order requested. |
| Dependencies | None. |
| 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 -
|
|
|
|