CosmosRP Posted February 9, 2012 Share Posted February 9, 2012 Hey guys: If I some multi-dimensional arrays, like so: array { array { [0]=> "Path1" [1]=> "10" } } array { array { [0]=> "Path2" [1]=> "16" } array { [0]=> "Path3" [1]=> "110" } } How can I add all of the values of key 1? I know its a foreach loop, but I can't figure it out... would it be this? Link to comment https://forums.phpfreaks.com/topic/256753-adding-array-values/ Share on other sites More sharing options...
Zane Posted February 9, 2012 Share Posted February 9, 2012 This is two multi-dimensional arrays.. but yeah, assuming you had one, you'd use a foreach $array = //multidimensional array $count = 0; foreach($array as $value) { if( is_array($value) { $count += $value[1]; } } Link to comment https://forums.phpfreaks.com/topic/256753-adding-array-values/#findComment-1316206 Share on other sites More sharing options...
Maq Posted February 9, 2012 Share Posted February 9, 2012 You can also use array_walk or a recursive call. Link to comment https://forums.phpfreaks.com/topic/256753-adding-array-values/#findComment-1316275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.