From this:
$arr = array( array('boo', 4), array('boo', 1), array('foo', 2), array('foo', 6) );
what is the best way to calculate this ?:
$arr = array( 'boo' => 5, 'foo' => 8 );
$sum = array(); for ( $i = 0; $i < count( $arr ); $i++ ) { if ( !isset( $sum[ $arr[$i][0] ] ) $sum[ $arr[$i][0] ] = 0; $sum[ $arr[$i][0] ] += $arr[$i][1]; } print_r( $sum );
Then:
$arr2 = array(); foreach($arr as $value) { if(isSet($arr2[$value[0]])) $arr2[$value[0]] += $value[1]; else $arr2[$value[0]] = $value[1]; }
Source: https://habr.com/ru/post/1770063/More articles:WPF Prism Deploys the same viewmodel in two forms - dependency-injectionHow can I conditionally import a package into Perl? - importhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1770060/creating-links-to-organizationcommunity-pages-in-liferay-6&usg=ALkJrhh-wN4Z5QxQcupclqnkMfgEu0w94gCustom maps in Android, loading via tiles (alternative for RouteMe for iPhone SDK) - androidComponent does not receive garbage collection - flexvb.net mantissa and counting exhibitors from double - mathhibernate 'open session in view' and asynchronous tasks - javaImproving php development reliability - version-controlUsing VS2010 to debug code executed in Linqpad - debuggingМогу ли я использовать Entity Framework для этого? - .netAll Articles