<?php
$promos = [
'1' => ['id' => '1', 'weight' => 1],
'2' => ['id' => '2', 'weight' => 2],
'3' => ['id' => '3', 'weight' => 3],
'4' => ['id' => '4', 'weight' => 4],
'5' => ['id' => '5', 'weight' => 5],
'6' => ['id' => '6', 'weight' => 6],
'7' => ['id' => '7', 'weight' => 7],
'8' => ['id' => '8', 'weight' => 8],
'9' => ['id' => '9', 'weight' => 9],
'10' => ['id' => '10', 'weight' => 10],
'11' => ['id' => '11', 'weight' => 11],
];
$cr['promos'] = [
'1' => ['id' => '1', 'weight' => 1],
'2' => ['id' => '2', 'weight' => 2],
'3' => ['id' => '3', 'weight' => 3],
'4' => ['id' => '4', 'weight' => 4],
'5' => ['id' => '5', 'weight' => 5],
'6' => ['id' => '6', 'weight' => 6],
'7' => ['id' => '7', 'weight' => 7],
'8' => ['id' => '8', 'weight' => 8],
'9' => ['id' => '9', 'weight' => 9],
'10' => ['id' => '10', 'weight' => 10],
'11' => ['id' => '11', 'weight' => 11],
];
$promo_weights = array_column($promos, 'weight', 'id');
array_multisort($promo_weights, SORT_ASC, $cr['promos']);
var_dump($cr['promos']);
- Output for 7.3.24 - 7.3.33, 7.4.12 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- array(11) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["weight"]=>
int(1)
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["weight"]=>
int(2)
}
[2]=>
array(2) {
["id"]=>
string(1) "3"
["weight"]=>
int(3)
}
[3]=>
array(2) {
["id"]=>
string(1) "4"
["weight"]=>
int(4)
}
[4]=>
array(2) {
["id"]=>
string(1) "5"
["weight"]=>
int(5)
}
[5]=>
array(2) {
["id"]=>
string(1) "6"
["weight"]=>
int(6)
}
[6]=>
array(2) {
["id"]=>
string(1) "7"
["weight"]=>
int(7)
}
[7]=>
array(2) {
["id"]=>
string(1) "8"
["weight"]=>
int(8)
}
[8]=>
array(2) {
["id"]=>
string(1) "9"
["weight"]=>
int(9)
}
[9]=>
array(2) {
["id"]=>
string(2) "10"
["weight"]=>
int(10)
}
[10]=>
array(2) {
["id"]=>
string(2) "11"
["weight"]=>
int(11)
}
}
preferences:
115.94 ms | 404 KiB | 114 Q