I'm a little stuck with some array sorting, maybe someone can help me out?
Given these two arrays:
$sortOrder = array(12, 20, 4);
$data = array(
(object)array(
'id' => 4,
'name' => 'Tom'
),
(object)array(
'id' => 12,
'name' => 'Bob'
),
(object)array(
'id' => 20,
'name' => 'Max'
)
)
I want to sort $data
by the id order specified in $sortOrder
.
So after sorting I want $data to be like this:
$data = array(
(object)array(
'id' => 12,
'name' => 'Bob'
),
(object)array(
'id' => 20,
'name' => 'Max'
),
(object)array(
'id' => 4,
'name' => 'Tom'
),
)
How would I do that?