Code:
<form action="" method="post">
Select your choice:
<select name="choice">
<option value="">Select</option>
<option value="1">Accending Order</option>
<option value="2">Descending</option>
</select>
<br />
<input type="submit" value="Submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$choice = $_POST['choice'];
$array = array(21,5,2,9,22,18);
if($choice ==1 ){
sort($array);
print "Sorted In Accending Order:<br />";
for($i=0;$i<count($array);$i++){
print $array[$i]."<br />";
}
}
else if($choice == 2){
rsort($array);
print "Sorted In Decending Order:<br />";
for($i=0;$i<count($array);$i++){
print $array[$i]."<br />";
}
}
else {
print "Wrong Choice";
}
}
?>
Comments
Post a Comment