Home >Backend Development >PHP Problem >PHP enters several numbers and sorts them from large to small
php Enter several numbers and sort them from large to small
The following program implements entering several numbers on the web page , the function of sorting and outputting from large to small, I hope it will be helpful to friends in need:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p>请输入要排序的数据</p> <form id="form1" name="form1" method="post" action=""> <input name="textfield" type="text" id="textfield" size="15" maxlength="15" />- <input name="textfield2" type="text" id="textfield2" size="15" />- <input name="textfield3" type="text" id="textfield3" size="15" />- <input name="textfield4" type="text" id="textfield4" size="15" />- <input name="textfield5" type="text" id="textfield5" size="15" /> <input type="submit" name="button" id="button" value="提交" /> </form> </body> </html> <?php if(isset($_POST['button'])){ echo "排序后的数据如下所示:"; echo '<br/>'; $array=array( "0"=>$_POST['textfield'], "1"=>$_POST['textfield2'], "2"=>$_POST['textfield3'], "3"=>$_POST['textfield4'], "4"=>$_POST['textfield5'],);//把数字存到数组中 rsort($array); foreach($array as $key => $value){ echo $value;//循环输出值 echo '<br/>'; } } ?>
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of PHP enters several numbers and sorts them from large to small. For more information, please follow other related articles on the PHP Chinese website!