<?php
$items = [
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
['a' => 'a', 'b' => 'b', 'c'=> 'c', 'd'=>'d', 'e'=>'e', 'f'=>'f'],
];
$iterations = 1000;
$start = microtime(true);
for ($i=0 ; $i<$iterations ; $i++) {
$reduced = array_reduce($items, fn($carry, $scope_items) => [...$carry, ...array_values($scope_items)], []);
}
$split = microtime(true);
for ($i=0 ; $i<$iterations ; $i++) {
$item_sets = [];
foreach ($items as $scope_items) {
$item_sets[] = array_values($scope_items);
}
$looped = array_merge(...$item_sets);
}
$end = microtime(TRUE);
echo "Reduce: " . ($split-$start)/$iterations . " sec\n";
echo "Merge: " . ($end-$split)/$iterations . " sec\n";
- Output for 8.1.24
- Reduce: 0.00026093888282776 sec
Merge: 9.9551677703857E-6 sec
preferences:
57.5 ms | 404 KiB | 5 Q