php - Addition of two matrix using loop -
these 2 matrices in 4 arrays:
array ( [0] => array ( [0] => 1 [1] => 2 ) [1] => array ( [0] => 4 [1] => 5 ) ) array ( [0] => array ( [0] => 1 [1] => 2 ) [1] => array ( [0] => 4 [1] => 5 ) )
how can add these matrices using loop?
try this:-
<?php $a1 = array('0' => array('0' => 1,'1' => 2),'1' => array('0' => 4,'1' => 5)); $a2 = array('0' => array('0' => 1,'1' => 2),'1' => array('0' => 4,'1' => 5)); $sumarray = array(); $result = array(); for($i=0; $i<=1; $i++) { for($j=0; $j<=1; $j++) { $result[$i][$j] = $a1[$i][$j] + $a2[$i][$j]; } } echo "<pre/>";print_r($result); ?>
output:- http://prntscr.com/75hoqi
Comments
Post a Comment