Space for google add

Display the elements of an array along with the keys ,size of array delete an element ,reverse the order of each element .

 


Q1) Write a menu driven program to perform the following operations on an

associative array:

i. Display the elements of an array along with the keys.

ii. Display the size of an array

iii. Delete an element from an array from the given index.

iv. Reverse the order of each element’s key-value pair [Hint: use array_flip()]

v. Traverse the elements in an array in random order [[Hint: use shuffle()].


seta1.html

<html>

<body>

<form method="post" action="seta1.php">

<input type='radio' name='op' value='1'>Display elements of array<br>

<input type='radio' name='op' value='2'>Display size of an array<br>

<input type='radio' name='op' value='3'>Delete an element from an array<br>

<input type='radio' name='op' value='4'>Reverse the order of array<br>

<input type='radio' name='op' value='5'>Traverse the elements in an array<br>

<input type='submit' name='submit' value='submit'>

</form>

</body>

</html>




seta1.php

<?php

$a=$_POST['op'];

$student=array('Name'=>'ritika','Roll no'=>10257,'Class'=>'TYBCS');

switch($a)

{

case 1:

foreach($student as $key=>$value)

{

echo "student $key is:$value\n<br>";

}

break;

case 2:

print_r($student);

$c=count($student);

echo "<br>size of array is {$c}<br>";

break;

case 3:

echo "previous array<br>";

print_r($student);

echo "<br>";

echo "sliced array<br>";

$d=array_splice($student,'Name');

print_r($d);

break;

case 4:

echo "previous array<br>";

print_r($student);

echo "<br>";

echo "flipped array<br>";

$b=array_flip($student);

print_r($b);

break;

case 5:

echo "previous array<br>";

print_r($student);

echo "<br>";

echo "shuffled array<br>";

shuffle($student);

print_r($student);

break;

}

?>



Post a Comment

0 Comments