Space for google add

Write a menu driven program to perform the following operations on associative arrays in PHP .



 Write a menu driven program to perform the following operations on

associative arrays:

1. Sort the array by values (changing the keys) in ascending, descending order.

2. Also sort the array by values without changing the keys.

3. Filter the odd elements from an array.

4. Sort the different arrays at a glance using single function.

5. Merge the given arrays.

6. Find the intersection of two arrays.

7. Find the union of two arrays.

8. Find set difference of two arrays.



a2setc2.html

<html>

<body>

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

<input type='radio' name='op' value='1'>Sort the array by values.<br>

<input type='radio' name='op' value='2'>Sort the array by values without changing the keys.<br>

<input type='radio' name='op' value='3'>Filter the odd elements from an array.<br>

<input type='radio' name='op' value='4'>Sort the different arrays at a glance using changing the keys. <br>

<input type='radio' name='op' value='5'>Merge the given array.<br>

<input type='radio' name='op' value='6'>Find the intersection of two array.<br>

<input type='radio' name='op' value='7'>Find the union of two array.<br>

<input type='radio' name='op' value='8'>Find set differnce of two arrays.<br>

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

</form>

</body>

</html>



a2setc2.php

<?php

$c=$_POST['op'];

$a=array('pen'=>15,'pencil'=>5,'rubber'=>3,'book'=>30);

$a1=array('pen'=>15,'ritika'=>57,'ram'=>3,'revati'=>30);

$a2=array(15,48,10,155,2,78);

function isodd($v)

{

if($v%2!=0)

return $v;

}

switch($c)

{

case 1:

print_r($a);

sort($a);

echo"<br>Array in ascending order<br>";

print_r($a);

rsort($a);

echo"<br>Array in desecending order";

echo "<br>";

print_r($a);break;


case 2:

print_r($a);

asort($a);

echo"<br>Array in ascending order<br>";

print_r($a);

arsort($a);

echo"<br>Array in desecending order<br>";

print_r($a);break;

case 3:

print_r($a);

echo "<br>";

echo"<br>Filter the odd elements from an array.<br>";

        print_r(array_filter($a,isodd));

break;

case 4:

print_r($a);echo "<br>";

print_r($a1);echo "<br>";

print_r($a2);echo "<br>";

array_multisort($a,$a1,$a2);

print_r($a);echo "<br>";

print_r($a1);echo "<br>";

print_r($a2);echo "<br>";

break;

case 5:

print_r($a);

echo "<br>";

print_r($a1);

echo "<br>Array Merge<br>";

print_r(array_merge($a,$a1));

break;

case 6:

print_r($a);

echo "<br>";

print_r($a1);

echo "<br>Array Intersection<br>";

print_r(array_intersect($a,$a1));

break;

case 7:

print_r($a);

echo "<br>";

print_r($a1);

echo "<br>Array Union<br>";

$union=array_merge($a,$a1);

print_r(array_unique($union));

break;

case 8:

print_r($a);

echo "<br>";

print_r($a1);

echo "<br>Array Differnce<br>";

print_r(array_diff($a,$a1));

break;


}

?>


Post a Comment

0 Comments