Write a menu driven program the following operation on an associative array - PHP | IProgramX

Slip no. 8. Write a menu driven program the following operation on an associative array
a) Reverse the order of each element’s key-value pair.
b) Traverse the element in an array in random order.


HTML file :

<html>
<body>
<form action="slip8_Q1.php" method="get">
<center>
<h3><input type="radio" name="op" value="1">Reverse the order of each elt's key-value pair</h3>
<h3><input type="radio" name="op" value="2">Traverse the elements in array in random order</h3>
<input type="submit" value="Submit">
</center>
</form>
</body>
</html>

PHP file :

<?php
                $op = $_GET['op'];
                $input = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
                switch($op)
                {
                                case 1 :  $flipped = array_flip($input);
                                                                 print_r($flipped);
                                                                  break;
                                case 2 :  shuffle($input);
                                                print_r($input);
                                                break;
                }
?>

Post a Comment

1 Comments