I want to get total of elements of each row at the end of that row and total of elements of each column at the end of each column.
For Example:
I have an array with digits values like this:
$twoDimArr = array( array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4"),
array("1" , "2" , "3" , "4")
);
output something like this:
$twoDimArr = array( array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"),
array("1" , "2" , "3" , "4", "total" => "10"))
"columnTotal => "array("7" , "14" , "21" , "28", "70")
);
Input Array: No of elements in rows may vary but no of each row element will be equal to other rows elements. indexes in input array may be anything.
I have coded this and it is working for me but I am not happy with the amount of code. May be someone will code more efficient and less code solution.
Thanks