![]() |
Sorting array
I am adding values from one array into another array. How would I sort the second array by the index numbers of the first.
example: PHP Code:
|
Eh you should be a little more detailed in your explanation, I'm not quite catching it.
And does this help at all? PHP Code:
|
ok Ill give some more detail:
PHP Code:
PHP Code:
How could I put this.secondarray in order from lowest to highest? So it will look like this: PHP Code:
|
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:
|
Ill give it a shot Thanks a bunch
|
I feel like I made a mistake >_>
Or like I'm forgetting something. I never did test to see if that works. Edit: Just tested, it works. :) Though that script would only work for that exact situation or something really similar. Its not exactly customizable and I'm too lazy to do anything more. |
heh well my situation is a little more complicated so I will take that and see if I can use it. Really I am doing: temp.array.add(temp.array1[i]@"-"@temp.array2[i]); and trying to sort temp.array using temp.array1's values
|
Quote:
PHP Code:
|
o.O
|
Just make a copy and delete in a random order until you have 2 or 7 or whatever.
|
how would that sort an array?
|
Quote:
|
Use
HTML Code:
object.insert(index, value); |
Yes, I could use that but the second array is shorter then the original array(the order to sort the second array)
|
All times are GMT +2. The time now is 09:07 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.