I have two multidimensional arrays in PHP, the first one being
[0] => [
'id' => 123,
'name' => 'John'
],
[1] => [
'id' => 456,
'name' => 'Anna'
],
[2] => [
'id' => 789,
'name' => 'Mario'
]
And the second one is like this:
[0] => [
'id' => 123,
'position' => 3
],
[1] => [
'id' => 456,
'position' => 1
],
[2] => [
'id' => 789,
'position' => 2
]
I'm trying to get a union of the two arrays without replacing any value. I just want to add 'position' to the first array and also sort by this new value in the meantime, like this:
[0] => [
'id' => 456,
'name' => 'Anna',
'position' => 1
],
[1] => [
'id' => 789,
'name' => 'Mario',
'position' => 2
],
[2] => [
'id' => 123,
'name' => 'John',
'position' => 3
]
How can achieve this result in the most efficient way? Thank you!