Skip to content
Advertisement

Sort PHP array through another array which specifies the sort order by value (values are not keys in first array)

I have two PHP-arrays and i want to sort the first by using the second. for example my first array could be:

JavaScript

If my second array now is this:

JavaScript

This second array always has values from 0 to n and no duplicates. I want to sort the first array by the numbers in the second so it should look like that:

JavaScript

How can i sort my array like that?

I asked this question before and i got referred to this question, but i can’t make out the solution for my case as i don’t know the keys and values in the first array. It should work for every key, so please don’t just refer me to this question again because i don’t get how this helps me.. Thanks

Advertisement

Answer

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement