Is there an easy way to sort an array with a variable array made for this task? For example:
$fruits [
'Apple' => '12',
'Cherry' => '10',
'Lemon' => '34',
'Peach' => '6'
]
$order [
1 => 'Peach',
2 => 'Other',
3 => 'Lemon',
4 => 'Other2',
5 => 'Apple',
6 => 'Cherry',
7 => 'Other3'
]
I'd like to return this kind of array:
$ordered_fruits [
'Peach' => '6',
'Lemon' => '34',
'Apple' => '12',
'Cherry' => '10'
]
make it with php functions:
$new = array_filter(array_replace(array_fill_keys($order, null), $fruits));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With