I need to to sort an array based on how I sorted a different array, here are 2 example arrays that I have that are linked based on their indexes (so $array1[0] and $array2[0] are relevant to eachother):
$array1 = Array (
'2',
'1',
'3'
);
$array2 = Array (
'linked_to_2',
'linked_to_1',
'linked_to_3',
);
As you can see $array1[0] is related to $array2[0], $array1[1] to $array2[1] and $array1[2] to $array2[2].
Now I create a new that uses the same values $array1 has but ordered like this:
$sorted_array1 = Array (
'1',
'2',
'3'
);
But I can't sort $array2 using the same method so how do I use $array1 and/or $sorted_array1 to create a sorted array using the values of $array2 like this:
$sorted_array2 = Array (
'linked_to_1',
'linked_to_2',
'linked_to_3',
);
For a bit of context in my actual use case I have a couple of ID's in the 1st array that I query against a database and in that database table with these ID's I order them by date of creation (which is another row in that db table). The values of array2 are not in this database table and can therefore not be sorted the same way.