DWPD : Practical 13
1.Write PHP Script using two dimensional arrays such as addition of two 2x2 matrices.<?php
$a1 = Array('0' => Array('0' => 1,'1' => 2),'1' => Array('0' => 4,'1' => 5));
echo "<pre/>";print_r($a1);
$a2 = Array('0' => Array('0' => 1,'1' => 2),'1' => Array('0' => 4,'1' => 5));
echo "<pre/>";print_r($a2);
$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 "Answer is<br/>";print_r($result);
?>
Output :
2.Write PHP Script to demonstrate use of associative arrays and for FOR EACH loop execution.<?php
$age = array("Department"=>"Computer", "Semester"=>"5th", "Enrolment No."=>"54");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Output :
This comment has been removed by a blog administrator.
ReplyDelete