Easy/quick – Combine Two Arrays By Value

I need a php function that will combine two arrays by value.

Example:
———-

Array 1 Data (Main List):

Array
(
[1] => Array
(
[id] => 1
[name] => James
)

[2] => Array
(
[id] => 2
[name] => Mark
)

[3] => Array
(
[id] => 3
[name] => John
)

[4] => Array
(
[id] => 4
[name] => Adam
)

[5] => Array
(
[id] => 5
[name] => Sue
)
)

Array 2 Data (To sort main list by):

Array
(
[0] => 4
[1] => 3
[2] => 1
[3] => 5
[4] => 2
)

The values of array 2 should match the values of array 1 for the key ‘id’.

The end result should display the list (array) in the following order

4 – Adam
3 – John
1 – James
5 – Sue
2 – Mark

Please PM questions

Leave a Reply

Your email address will not be published. Required fields are marked *