php随机取出各个位上的数字
AndyYang|
阅读:1243
发表时间:2010-04-18 23:56:00
php
摘要:用php实现随机取出各个位上的数字,代码附上:
<?php
$a=mt_rand(0,123456789);
$num=$a;
$num1=$num%10;
$num=($num-$num1)/10;
$num2=$num%10;
$num=($num-$num2)/10;
$num3=$num%10;
$num=($num-$num3)/10;
$num4=$num%10;
$num=($num-$num4)/10;
$num5=$num%10;
$num=($num-$num5)/10;
$num6=$num%10;
$num=($num-$num6)/10;
$num7=$num%10;
$num=($num-$num7)/10;
$num8=$num%10;
$num=($num-$num8)/10;
$num9=$num%10;
echo "随机数是:{$a}<br>";
echo "亿位是{$num9}\t";
echo "千万位是{$num8}\t";
echo "百万位是{$num7}\t";
echo "十万位是{$num6}\t";
echo "万位是{$num5}\t";
echo "千位是{$num4}\t";
echo "百位是{$num3}\t";
echo "十位是{$num2}\t";
echo "个位是{$num1}\t";
?>
已有0条评论