我有一个数组A
作为排序数组的基础,但是,如果数组中不存在B
元素,我想保留它的位置。B
A
$A = array (
0 => 'Peter',
1 => 'John',
2 => 'Mike',
3 => 'Josh',
4 => 'Bob',
5 => 'Jan'
);
$B = array (
0 => array ('name' => 'Aaron'),
1 => array ('name' => 'Adam'),
2 => array ('name' => 'Bob'),
3 => array ('name' => 'Jan'),
4 => array ('name' => 'John'),
5 => array ('name' => 'Matt'),
6 => array ('name' => 'Mike'),
7 => array ('name' => 'Peter'),
);
所以B
在根据排序后会变成A
$B = array (
0 => array ('name' => 'Aaron'), // keep position since is not in `A`
1 => array ('name' => 'Adam'), // keep position since is not in `A`
2 => array ('name' => 'Peter'), // move it up since is first pos in `A`
3 => array ('name' => 'John'),
4 => array ('name' => 'Mike'),
5 => array ('name' => 'Bob'),
6 => array ('name' => 'Jan'),
7 => array ('name' => 'Matt'),
);
我怎么能像这样对它进行排序?