初学者在这里,请解释一下不同答案的原因。
$string = "If you’re looking for a way";
$pos = 0;
while (($pos = strpos($string,"o",$pos))!== false) {
echo $pos."<br/>";
$pos++;
}
[上述代码的结果] 输出为:
4
13
14
21
$pos = 0;
$string = "If you’re looking for a way";
while ((strpos($string,"o",$pos))!== false) {
echo strpos($string,"o",$pos)."<br/>";
$pos++;
}
[上述代码的结果] 输出为:
4
4
4
4
4
13
13
13
13
13
13
13
13
13
14
21
21
21
21
21
21
21