The array is formed as follows:
$arr[] = [1,2,3] $arr[] = [2,3,5] $arr[] = [1,1,1] At the output you need to get one array: [4,6,9]
How to make the most beautiful?
The array is formed as follows:
$arr[] = [1,2,3] $arr[] = [2,3,5] $arr[] = [1,1,1] At the output you need to get one array: [4,6,9]
How to make the most beautiful?
foreach ($arr as $value1lvl) { foreach ($value1lvl as $key2lvl=>$value2lvl) { if (!isset($sum[$key2lvl])) {$sum[$key2lvl]=0;} $sum[$key2lvl]=$sum[$key2lvl]+$value2lvl; } } Demo - http://sandbox.onlinephpfunctions.com/code/a27992153fdfc46fc4b36242b619347f25a9b768
Source: https://ru.stackoverflow.com/questions/641157/
All Articles