Whatever message this page gives is out now! Go check it out!
StructToSorted(struct, sorttype, sortorder, localeSensitive)<!--- Syntax with callback function--->
StructToSorted(struct,callback)Parameter | Description |
struct | The structure to be sorted. |
sortType | Sort types are text or numeric. Text value produces a case-insensitive sort. |
sortOrder | Ascending (" asc ") or descending ("desc"). |
localeSensitive | True or false. |
callback | The callback function to be used. The function compares the values in a struct and returns -1,0, and 1 depending on the values. |
<cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
mystr=StructToSorted(mystruct,"text","asc",false);
writedump(mystr);
</cfscript><cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
callback=function(value1,value2,key1,key2)
{
if (key1>key2)
return 1;
else
return -1;
};
mystr=StructToSorted(mystruct,callback);
writedump(mystr);
</cfscript><cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
mystr=mystruct.ToSorted("text","asc",false);
writedump(mystr);
</cfscript><cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
callback=function(value1,value2,key1,key2)
{
if (key1>key2)
return 1;
else
return -1;
};
mystr=mystruct.ToSorted(callback);
writedump(mystr);
</cfscript>