TY_BCS_PHP_SLIP 18_1




Slip no. 18. Write a menu driven program to perform the following operation on an associative array.
a) Display the elements of an array along with key.
b) Display the size of an array.
HTML file :
<html>
<body>
<form action=slip18_1.php>
Select Option:<br>
<input type=radio name=a value=1>Display Array Along With Their Keys<br>
<input type=radio name=a value=2>Display Size of An Array<br>
<input type=submit value=SUBMIT>
</form>
</body>
</html>

PHP file :
<?php
$a = array("Raj"=>"35","Ramesh"=>"37","Jay"=>"43");
$ch = $_GET['a'];
switch($ch)
{
                                case 1  :  foreach($a as $x=>$x_value)
                                                 {
                                                                echo "Key = " . $x . ", Value = " . $x_value;
                                                                echo "<br>";
                                                 }
                                                break;

                                case 2  :  $l = sizeof($a);
                                                echo $l;
                                                break;
}
?>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.