Differences

This shows you the differences between the selected revision and the current version of the page.

ptpscript:functions:sort 2006/05/27 15:38 ptpscript:functions:sort 2007/01/24 10:15 current
Line 6: Line 6:
\\ \\
**Syntax** **Syntax**
-  * ''[[PTPScript:Types:Array|Array]] sort( [[PTPScript:Types:Array|Array]] subject [, [[PTPScript:Types:Boolean|Boolean]] reverse [, [[PTPScript:Types:Number|Number]] type [, [[PTPScript:Types:Number|Number]] method ] ] ] )''+  * ''[[PTPScript:Types:Array|Array]] sort( [[PTPScript:Types:Array|Array]] subject [, [[PTPScript:Types:Boolean|Boolean]] reverse [, [[PTPScript:Types:Boolean|Boolean]] preserve [, [[PTPScript:Types:Boolean|Boolean]] byKey [, [[PTPScript:Types:Boolean|Boolean]] safe [, [[PTPScript:Types:Number|Number]] method ] ] ] ] ] )''
\\ \\
Line 14: Line 14:
    * **''false''** (default) - ''subject'' will be sorted from lowest to highest.     * **''false''** (default) - ''subject'' will be sorted from lowest to highest.
    * **''true''** - ''subject'' will be sorted from highest to lowest.     * **''true''** - ''subject'' will be sorted from highest to lowest.
-  * [[PTPScript:Types:Number|Number]] ''type'' - Array key options+  * [[PTPScript:Types:Boolean|Boolean]] ''preserve'' - Whether to preserve item keys
-    * ''0'' (default) - Sort by item values, and re-assign keys+    * **''false''** (default) - Keys will be re-assigned
-    * ''1'' - Sort by item values, and preserve keys+    * **''true''** - Keys will be preserved. 
-    * ''2'' - Sort by item keys.+  * [[PTPScript:Types:Boolean|Boolean]] ''byKey'' - Whether to sort by item key
 +    * **''false''** (default) - ''subject'' will be sorted by item value. 
 +    * **''true''** - ''subject'' will be sorted by item key. 
 +  * [[PTPScript:Types:Boolean|Boolean]] ''safe'' - Whether to use "safe" sorting. 
 +    * **''false''** (default) - ''subject'' will be sorted using quicksort, which is not "safe". 
 +    * **''true''** - ''subject'' will be sorted using a merge sort, which is "safe".
  * [[PTPScript:Types:Number|Number]] ''method'' - Sort method options.   * [[PTPScript:Types:Number|Number]] ''method'' - Sort method options.
-    * ''0'' (default) - Compare items normally, without changing type.+    * ''0'' (default) - Compare items using standard comparison.
    * ''1'' - Compare items numerically.     * ''1'' - Compare items numerically.
-    * ''2'' - Compare items as strings. +    * ''2'' - Compare items as case-sensitive strings. 
-    * ''3'' - Compare items as strings, using case-sensitive [[http://sourcefrog.net/projects/natsort/|natural ordering]]. +    * ''3'' - Compare items as case-insensitive strings
-    * ''4'' - Compare items as strings, using case-insensitive [[http://sourcefrog.net/projects/natsort/|natural ordering]]. +    * ''4'' - Compare items as case-sensitive strings, using [[http://sourcefrog.net/projects/natsort/|natural ordering]]. 
-    * ''5'' - Compare items as strings, based on the current system locale.+    * ''5'' - Compare items as case-insensitive strings, using [[http://sourcefrog.net/projects/natsort/|natural ordering]]. 
 +    * ''6'' - Compare items as case-sensitive strings, according to locale. 
 +    * ''7'' - Compare items as case-insensitive strings, according to locale.
\\ \\
Line 31: Line 38:
</box> </box>
-Returns ''subject'' sorted in order according to various options.+Returns ''subject'' sorted in order according to various options.
-<note important+<note tip
-[[http://sourcefrog.net/projects/natsort/|Natural ordering]] cannot be used with key preservation (when ''type'' is ''1'') or sorting by key (when ''type'' is ''2''), so ''type'' will be forced to ''0'' in this case.+Key value, type, and order do not matter - the Array does not have to be numerically indexed.
</note> </note>
-~~DISCUSSION~~+<note tip> 
 +"Safe" sorting is where two identical items will retain their original order. Sometimes this is not important, and so the quickest sorting method can be used (which here is an enhanced version of quicksort). At other times, it is important for identical keys to retain their relative order, in which case the slightly slower (but safe) merge sort will be used. 
 +</note> 
 + 
 +For more information about comparison methods, see the ''[[PTPScript:Functions:compare|compare()]]'' function. 
 + 
 
 
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki