Last active
June 24, 2017 01:14
-
-
Save globalideias/fac66df2f913178080a8625b8f6e277a to your computer and use it in GitHub Desktop.
Soma dados de um array vertical e horizontal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servs['SERVICO1'][1] = 10; | |
$servs['SERVICO1'][2] = 30; | |
$servs['SERVICO1'][3] = 1; | |
$servs['SERVICO2'][1] = 20; | |
$servs['SERVICO2'][2] = 40; | |
$servs['SERVICO2'][3] = 2; | |
$servs['SERVICO3'][1] = 100; | |
$servs['SERVICO3'][2] = 110; | |
$servs['SERVICO3'][3] = 3; | |
$total_horizontal = []; | |
$total_vertical = []; | |
//var_dump($servs); | |
//echo "<br/>"; | |
foreach($servs as $k => $v){ | |
//var_dump(array_sum($servs[$k])); | |
//echo "<br/>"; | |
$total_horizontal[$k] = array_sum($servs[$k]); | |
foreach($v as $coluna => $valor){ | |
if(!isset($total_vertical[$coluna])){ | |
$total_vertical[$coluna] = $valor; | |
}else{ | |
$total_vertical[$coluna] += $valor; | |
} | |
} | |
} | |
var_dump($total_horizontal); | |
echo "<br/>"; | |
var_dump($total_vertical); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment