$a= [ '1' => ['key'=>'1','id'=>'4' ],
'2' => ['key'=>'2','id'=>'1' ],
'3' => ['key'=>'3','id'=>'5' ]
]
$b = [1,5]
so i want to sort array $a so that if $a[*]['id'] is in $b array it should be first.
so in this example the out put should be
$a = ['2' => ['key'=>'2','id'=>'1' ],
'3' => ['key'=>'3','id'=>'5' ]
'1' => ['key'=>'1','id'=>'4' ],
]
i tried
uasort($a, function($k, $v) use ($b) {
return in_array($v['id'],$b) ? 1 : -1;
});
yet failed :(
is there an optimum method for doing such a trick using any of the php sorting functions?
uasort()?