在PHP中对用户输入进行排序

时间:2017-09-07 07:25:03

标签: php sorting

我还是PHP的初学者,我想知道如何在PHP中对用户输入进行排序。我知道这不起作用,但我想知道一种更简单的方法。输入必须是用逗号分隔的整数。提前谢谢。

 <?php
          //MUST SORT USER INPUT  
          $user_input=$_POST['sort'];
          sort($user_input);
          echo $user_input . ',' ;       
 ?>
<form method='post' action=''>
<input name='arrange' type='text' id='arrange'/>
<input type='submit' class='btn btn-primary' name='submit' value='Submit' />
</form>

1 个答案:

答案 0 :(得分:1)

解决方案

<?php
    if(isset($_POST['submit']) {
        $input = explode(',', $_POST['arrange']);
        sort($input);
        echo implode(',', $input);  
    }
?>

<form method="POST">
    <input name='arrange' type='text' id='arrange'/>
    <input type='submit' class='btn btn-primary' name='submit' value='Submit' />
</form>