function merge(...$arrays) {
$result = [];
foreach ($arrays as $arr) {
foreach ($arr as $key => $values) {
if (!isset($result[$key])) {
$result[$key] = [];
}
for ($i = 0; $i < count($values); $i++) {
$result[$key][$i] = ($result[$key][$i] ?? 0) + $values[$i];
}
}
}
return $result;
}
$arr = merge($arr1, $arr2);
SELECT * FROM 'users'
function rotateArray($arr, $shift) {
$shift %= count($arr);
array_unshift($arr, ...array_splice($arr, -$shift));
return $arr;
}
$arr = range(1, 7);
echo implode(', ', rotateArray($arr, 1)); // 7, 1, 2, 3, 4, 5, 6
echo implode(', ', rotateArray($arr, -3)); // 4, 5, 6, 7, 1, 2, 3
echo implode(', ', rotateArray($arr, 69)); // 2, 3, 4, 5, 6, 7, 1
$namesPartsArrays = [ $firstname, $lastname ];
$namesCount = 5;
$rand = fn($arr) => array_map(fn($n) => $arr[$n], array_rand($arr, $namesCount));
$namesParts = array_map($rand, $namesPartsArrays);
$names = implode(', ', array_map(fn(...$parts) => implode(' ', $parts), ...$namesParts)).'.';
$grouped = [];
foreach ($arr as $key => $val) {
$grouped[explode('_', $key)[0]][$key] = $val;
}