$arr = array(
array(1, 2, 3, 5),
array(4, 5, 6, 5),
array(7, 8, 9, 5)
);
$rows = count($arr);
$cols = count($arr[0]);
for ($i = 0; $i < $rows; $i++) {
echo "Sum of row " . $i . " = " . array_sum($arr[$i]) . "\n";
}
for ($i = 0; $i < $cols; $i++) {
echo "Sum of col " . $i . " = " . array_sum(array_column($arr, $i)) . "\n";
}
/*
run:
Sum of row 0 = 11
Sum of row 1 = 20
Sum of row 2 = 29
Sum of col 0 = 12
Sum of col 1 = 15
Sum of col 2 = 18
Sum of col 3 = 15
*/