dongshao1156 2011-10-30 10:43
浏览 282
已采纳

如何对数字中的每个数值进行排序?

I am making a PHP login/register form and to confirm whether someone is actually human and not a bot I am generating a random value that has to be written in a certain way. For example:

Please write the following number in an increasing manner: 34745 The user should write 34457 and only then will the confirmation work.

The thing is I know how to use the rand() function, that's how I generate the number. But the problem is I do not know how to make PHP sort the generated number's numerical values (for ex.: 64348 -> 34468). How do I do this? I hope there is a single function for that, as I've seen numerous ways to sort arrays and since they have indexes I only suppose that it should be possible to sort a number's values.

  • 写回答

3条回答 默认 最新

  • duanfan1965 2011-10-30 10:53
    关注
    <?php
    
    $number = str_split("647214");
    
    sort($number);
    $number = implode($number);
    
    echo $number;
    
    ?>
    

    Demo: http://codepad.viper-7.com/RepImd

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?