3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
55.31 ms | 402 KiB | 5 Q