# Is there a "User Function"-Type sorting available in AS?

**URL:** <https://forum.kirupa.com/t/is-there-a-user-function-type-sorting-available-in-as/196831>\
**Category:** flash\
**Created:** [August 11, 2006, 8:28am UTC](https://forum.kirupa.com/t/is-there-a-user-function-type-sorting-available-in-as/196831 "2006-08-11T08:28:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CEOofAEP](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@CEOofAEP](https://forum.kirupa.com/u/CEOofAEP)\
**Post date:** [August 11, 2006, 8:28am UTC](https://forum.kirupa.com/t/is-there-a-user-function-type-sorting-available-in-as/196831/1 "2006-08-11T08:28:18Z")

</div>

Hello again-

as always, I only drop by when _I_ have a problem… I’m such a selfish bastard (is it allowed to even say “bastard” on here?) :jail:

Anyways. I know that (in PHP) there’s a way to use user-created functions to sort an Array (_ **usort** _ & _ **uksort** _) by custom comparisons- you pass the Array and the name of your function and it uses your own function to “re-organize” the array.

Is something like that also available / possible in Actionscript? Or do I have to write my own function where it loops through the array entries and writes them into a new array? I need it relatively quick so setting up my own might take too long.

The setup is pretty much this (just in case you’re interested):

```auto
my_array[0]["name"] = "Bob"
my_array[0]["number"] = "11"
my_array[1]["name"] = "Peter"
my_array[1]["number"] = "22"
my_array[2]["name"] = "Justus"
my_array[2]["number"] = "33"

```

**Now comes the part that makes me require a user function…**  
I have \*another \*array, that contains a custom order to be applied to the main array (my\_array):

```auto
sort_array[0] = "22"
sort_array[1] = "33"
sort_array[2] = "11"

```

What I need is a function that will process “my\_array” and re-order it so that the entries in “my\_array” are in the order that matches the “number” field (from “my\_array”) to the order of the number values in the array “sort\_array”.

I hope the example makes sense… basically, what I need is (going by above’s example) a result where “my\_array” will end up ordered like this:

```auto

my_array[1]["name"] = "Peter"
my_array[1]["number"] = "22"
my_array[2]["name"] = "Justus"
my_array[2]["number"] = "33"
my_array[0]["name"] = "Bob"
my_array[0]["number"] = "11"

```

(ordered by “number” in connection to the sequence in which the numbers are in “sort\_array”)

It doesn’t matter to me if it will create a new array- or if the keys will be retained or re-set… I just need the array to be sorted ^^;

Thanks for all you people’s time and effort!

~Marcel
