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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -