<?php
$ids = [1,2,3,4,5,6,7,8,9,10];
function createMultipleFromArticles($productsId): array
{
// It can be possible to have multiple product in the same page
$productsId = array_unique($productsId);
$positions = array_flip($productsId);
$products = [1,4,6,7,9,10,2,3,5,8];
$products = array_combine($productsId, $products);
var_export($products);
return array_map(function (int $productId) use ($products, $positions) {
return [$products[$productId], $positions[$productId] + 1];
// return $this->create($products[$productId], $positions[$productId] + 1);
}, $productsId);
}
var_export(createMultipleFromArticles($ids));
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array (
1 => 1,
2 => 4,
3 => 6,
4 => 7,
5 => 9,
6 => 10,
7 => 2,
8 => 3,
9 => 5,
10 => 8,
)array (
0 =>
array (
0 => 1,
1 => 1,
),
1 =>
array (
0 => 4,
1 => 2,
),
2 =>
array (
0 => 6,
1 => 3,
),
3 =>
array (
0 => 7,
1 => 4,
),
4 =>
array (
0 => 9,
1 => 5,
),
5 =>
array (
0 => 10,
1 => 6,
),
6 =>
array (
0 => 2,
1 => 7,
),
7 =>
array (
0 => 3,
1 => 8,
),
8 =>
array (
0 => 5,
1 => 9,
),
9 =>
array (
0 => 8,
1 => 10,
),
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
1 => 1,
2 => 4,
3 => 6,
4 => 7,
5 => 9,
6 => 10,
7 => 2,
8 => 3,
9 => 5,
10 => 8,
)array (
0 =>
array (
0 => 1,
1 => 1,
),
1 =>
array (
0 => 4,
1 => 2,
),
2 =>
array (
0 => 6,
1 => 3,
),
3 =>
array (
0 => 7,
1 => 4,
),
4 =>
array (
0 => 9,
1 => 5,
),
5 =>
array (
0 => 10,
1 => 6,
),
6 =>
array (
0 => 2,
1 => 7,
),
7 =>
array (
0 => 3,
1 => 8,
),
8 =>
array (
0 => 5,
1 => 9,
),
9 =>
array (
0 => 8,
1 => 10,
),
)
preferences:
173.78 ms | 403 KiB | 188 Q