How to sort an array by values of another array?

The two arrays
$arr = ['banan','apple'];
$arr2 = ['apple','banan','pear'];

Need to do sorting on the first array, although it is shorter than the second, to such array
['banan','apple','pear'];
March 19th 20 at 09:03
1 answer
March 19th 20 at 09:05
Solution
This is what you need
array_multisort
PHP warning: array_multisort(): Array sizes are inconsistent
size does not match - Ramon_Kilback26 commented on March 19th 20 at 09:08
@Ramon_Kilback26,

nonsense in my opinion, but if I try
$arr = ['banan','apple'];
$arr2 = ['apple','banan','pear'];
$arr = array_pad($arr, count($arr2), 0);

array_multisort($arr, $arr2);
print_r($arr2);
- Will_Jacobson11 commented on March 19th 20 at 09:11
@Will_Jacobson11works - Ramon_Kilback26 commented on March 19th 20 at 09:14

Find more questions by tags PHP