Home > Backend Development > PHP Tutorial > 下面这段怎么理解

下面这段怎么理解

WBOY
Release: 2016-06-23 13:45:15
Original
874 people have browsed it

$str="1234567890";
$s='';

for($i=0;$i {
    $k=mt_rand(1, strlen($str));
    $s.=$str[$k-1];
}

我也知道是循环随机数,但是为啥一次出来的是四个呢


回复讨论(解决方案)

for 循环里面不是有条件 $i

for($i=0;$i {
    $k=mt_rand(1, strlen($str));
    $s.=$str[$k-1];
}

循环了4次,当然是一次4个了。很正常啊。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template