Whatever message this page gives is out now! Go check it out!
StructSort(struct [, sortType[, sortOrder[, path[, localeSensitive]]]])StructSort(struct,callback)Parameter | Description |
struct | A ColdFusion structure |
sortType |
|
sortOrder |
|
path | String or a variable that contains one. Path to apply to each top-level key, to reach element value by which to sort. The default value is nothing (top-level entries sorted by their own values). |
localeSensitive | Specify if you wish to do a locale-sensitive sorting. The default value is false. |
callback | A function which takes two keys of the struct, and returns whether the first value if greater than, equal to, or less than the second value. |
<cfscript>
myStruct=StructNew();
myStruct={a="London",b="Paris",c="Berlin",d="New York",e="Dublin"};
mySort=StructSort(myStruct,"text","asc"); //Sorts the top level keys in the struct in ascending order
WriteOutput(serializeJSON(mySort));
</cfscript><cfscript>
myStruct={a="London",b="Paris",c="Berlin",d="New York",e="Dublin"};
myNewSort=myStruct.sort("text","asc");
WriteDump(myNewSort);
</cfscript><cfscript>
myStruct=StructNew();
myStruct={a="London",b="Paris",c="Berlin",d="New York",e="Dublin"};
// define callaback function
function callback(e1, e2){
return compare(e1, e2);
}
mySort=StructSort(myStruct,callback);
writedump(mySort);
</cfscript>