Web Technologies

Web Technologies 

Slip27

Q.1)  Write a PHP Script for the following: 
a. Declare a Multidimensional Array. 
b. Display specific element from a Multidimensional array.  
c. Also delete given element from the Multidimensional array. 
d. Display an array. 
e. Search a given element from an array.   [Marks30] 

Solution

a.php
<?php

$mat=array(array(7,3,4),array(8,6,5),array(9,2,4));
$row=$_POST['r'];
$col=$_POST['c'];
$op=$_POST['op'];

switch($op)
{
case 'disp':
  display($mat);
echo "Value at row $row,column $col is {$mat[$row][$col]}";
break;
case 'delete':
echo "Before Delete :<br>";
display($mat);
unset($mat[$row][$col]);
echo "After Delete :<br>";
display($mat);
}
function display($mat)
{
echo "<table border=1>";
foreach($mat as $row)
{
echo "<tr>";
foreach($row as $v)
echo "<td>$v</td>";
echo "</tr>";
}
echo "</table><br>";
}

?>

b.html
<form method='post' action='a.php'>
Enter Row :<input type='text' name='r'><br>
Enter Column :<input type='text' name='c'><br>
Select Option :<br>
<input type='radio' name='op' value='disp'>Display
<input type='radio' name='op' value='delete'>Delete
<br>
<input type='submit'>
<input type='reset'>
</form>

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post