[
[0] => [
[course_id] => 100
[name] => Организация работы в летних оздоровительных лагерях
]
[1] => [
[course_id] => 50
[name] => Педагогическое образование: учитель технологии
]
[2] => [
[course_id] => 150
[name] => Специалист в сфере закупок
]
]
[
[0] => [
[course_id] => 150
]
[1] => [
[course_id] => 50
]
[2] => [
[course_id] => 100
]
]
$a1 = array_column($a1, null, 'course_id');
$sorted = array_map(function($v) use ($a1) {
return $a1[$v];
}, array_column($a2, 'course_id'));
print_r($sorted);
$sorted = [];
foreach($order as $oitem) {
foreach ($unsorted as $key => $uitem) {
if($oitem['course_id'] == $uitem['course_id']) {
$sorted[] = $uitem;
unset($unsorted[$key]);
break;
}
}
}
foreach ($unsorted as $uitem) {
$sorted[] = $uitem;
}
var arr1 = [
{course_id: 50, name: "name 1"},
{course_id: 150, name: "name 2"},
{course_id: 100, name: "name 3"}
]
var arr2 = [
{course_id: 150},
{course_id: 50},
{course_id: 100}
]
var res = arr1.map((el,idx) => {
el.course_id = arr2[idx].course_id
return el
}).sort((a,b) => a.course_id-b.course_id)
console.log(res)