我尝试使用php代码生成随机(3个数字)数字,但是当我尝试返回值时它不起作用

时间:2013-02-12 13:37:09

标签: php function recursion return

这是我的PHP脚本: 当我尝试将值返回$ total和echo函数generate_random_3之后,在某些情况下它不生成任何数字,请帮助

<?php
    function generate_random_3(){

        for($x=0; $x<3; $x++){
            $random[] = rand(1, 9);
        }
        list($first, $second, $third) = $random;

        if($first!=$second AND $first!=$third AND $second!=$third AND $first!=0){
            $total = $first.$second.$third;
            return $total;
            }else{
            generate_random_3();
            }
    }
    echo generate_random_3();
?>

2 个答案:

答案 0 :(得分:1)

function generate_random_3() {
  return rand(100,999);
}

echo generate_random_3();

答案 1 :(得分:0)

无论如何......

$number1 = rand(0,365);
$number2 = rand(0,365);
$number3 = rand(0,365);


echo $number1 . " " . $number2 . " " . $number3;