当前位置:Gxlcms > PHP教程 > 代码不懂解决方法

代码不懂解决方法

时间:2021-07-01 10:21:17 帮助过:5人阅读

代码不懂
//将四个数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$im = imagecreate(60,20)
$strx=rand(3,8);
for($i=0;$i<4;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos, substr($num,$i,1), $black);
$strx+=rand(8,12);
}



上面的代码的$strx=rand(3,8);$strx+=rand(8,12);这两句不是很明白,这两句怎么将$im的60平分呢,还是这里根本不是平分,可以帮我解释一下这两句代码的意思吗?特别是$strx+=rand(8,12);这句,先谢谢了




------解决方案--------------------
$strx += rand(8,12); 是 $strx = $strx + rand(8,12); 的简写
------解决方案--------------------
精神可嘉,但缺乏灵活性
PHP code
$strx = 8;//rand(3,8) 介于 3 到 8 之间,取最大值 8
for($i=0; $i<4; $i++) {
  echo $strx += 12;//rand(8,12) 介于 8 到 12 之间,取最大值 12
  echo '
'; }

人气教程排行