<html>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Select options:
<input type="radio" value="Sort the keys" name="d1">Sorting of Keys</input>
<input type="radio" value="Sort the values" name="d1">Sorting of values</input>
<input type="radio" value="Odd elements" name="d1">Filter the odd elements</input>
<input type="radio" value="Multisort" name="d1">Sort the different arrays at a glance using single function</input>
<input type="radio" value="Merge" name="d1">Merge the Arrays</input>
<input type="radio" value="Intersection" name="d1">Intersection of two Arrays</input>
<input type="radio" value="Union" name="d1">Union of two Arrays</input>
<input type="radio" value="Difference" name="d1">Difference of two Arrays</input>
<input type="submit">
</form>
<?php
echo "
Associative ARRAY.1......";
$a = array("one"=>"1","two"=>"2","three"=>"3");
echo "
Associative ARRAY.2......
";
$a1 = array("four"=>"4","two"=>"2","six"=>"6");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$op=$_POST['d1'];
if($op == 'Sort the keys')
{
echo"Ascending order
";
sort($a);
foreach($a as $k => $v)
{
echo "Key $k Value $v
";
}
echo"Descending order
";
rsort($a);
foreach($a as $k => $v)
{
echo "Key $k Value $v
";
}
}
else if($op == 'Sort the values')
{
echo"Ascending order
";
asort($a);
foreach($a as $k => $v)
{
echo "Key $k Value $v
";
}
echo"Descending order
";
arsort($a);
foreach($a as $k => $v)
{
echo "Key $k Value $v
";
}
}
else if($op == 'Odd elements')
{
echo "Odd elements";
function test_odd($var)
{
return ($var &1);
}
print_r(array_filter($a,"test_odd"));
}
else if($op =='Multisort')
{
$b1=array_multisort($a,$a1);
print_r($b1);
}
else if($op =='Merge')
{
print_r(array_merge($a,$a1));
}
else if($op =='Intersection')
{
$r = array_intersect($a1,$a);
print_r($r);
}
else if($op =='Union')
{
$b=array_unique(array_merge($a,$a1));
print_r($b);
}
else if($op =='Difference')
{
$b1=array_diff($a,$a1);
print_r($b1);
}
}
?>
</body>
</html>