addition of 2D(2*2 matrices) array in php.
Hellow.
}
?>
So today we are sharing a small program which adds elements of 2D Array.
<?php
$a=array(
array(10,20),
array(12,22)
);
);
$b=array(
array(11,22),
array(10,21)
);
);
$c=array();
for($i=0;$i<count($a);$i++){
for($j=0;$j<count($a);$j++){
echo "a[$i][$j]";
echo $a[$i][$j]."<br/>";
}
}
}
echo "<br/>";
for($i=0;$i<count($a);$i++){
for($j=0;$j<count($a);$j++){
echo "b[$i][$j]";
echo $b[$i][$j]."<br/>";
}
}
}
echo "<br/>";
echo "addition of two matrix:<br> <br>";
for($i=0;$i<count($a);$i++){
for($j=0;$j<count($a);$j++){
$c[$i][$j]=$a[$i][$j]+$b[$i][$j];
echo "c[$i][$j]";
echo $c[$i][$j]."<br/>";
}
}
?>
No comments: