Extracting specific lines from multidimensional array and applying math

$the_array = array
(		 "0"=>array
		 						 (
								 "Name1",
		 						 "20",
								 "name1_img",
								 "name1 description.",
								 ),
		"1"=>array
								 (
								 "Name2",
		 						 "40",
								 "name2_img",
								 "name2 description.",
								 ),
);

I’m looking for a way to just extract the line with a number value from each array and add them together. For example, adding the 20 and 40 together. I have many more than just these 2 data sets, so I’m trying to dynamically create a total number as I add more information.

I’ve tried using array_walk and adding the values together, but it just concatenates them no matter what I do. Can anyone help me? :slight_smile:

Thank you!


$sum = 0;
foreach ($the_array as $sub_array) {
    $sum += $sub_array[1];
}