Skip to content
Advertisement

how to sort php multidimensional array by other array

I have an array with IDs that looks like

JavaScript

and another multidimensional array that looks like

JavaScript

i tried

JavaScript

The order_ids of the 2nd array correspond to the values in the first array. What I need to do is sort the 2nd array by the order_ids in the order they are in the 1st array.

Advertisement

Answer

You could cycle through the records in $arr and store them in the order set by $order_ids – result in $newArr:

JavaScript

demo

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