3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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));
based on N8d5g
Output for hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
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 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/QgmVM on line 5
Process exited with code 255.