Thread: Sorting array
View Single Post
  #4  
Old 02-06-2007, 12:19 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Well you would need an array of their correct positions obviously. Then make a second array in the function which will be the one you're going to return. Then use a for loop on the first array, and if you find that element in second array add it to the array you're going to return. It would end up in correct order.

PHP Code:
function onCreated() {
  
this.firstarray = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
  
this.secondarray sort({"Three","Nine","Five","Four"});
}
function 
sort(inarray) {
  
temp.outarray;
  
temp.i;
  
temp.e;
  
temp.inarray.size();
  
temp.sortarray this.firstarray;
  for (
0sortarray.size() && 0++) {
    
sortarray[i];
    if (
inarray.index(e) > -1) {
      
outarray.add(e);
      
c--;
    }
  }
  return 
outarray;

That should be the simplest version.
__________________

Last edited by Inverness; 02-06-2007 at 12:33 AM..
Reply With Quote