循环中的strpos问题

时间:2014-09-14 09:52:18

标签: php while-loop strpos

我的问题主要是关于“while条件”,当在shuld返回“FALSE”时显然返回“TRUE”。这是代码:

<?php
$sentence='is is is';
$search='is';
$length=strlen($search);
$offset=0;
$j=1;
while(($pos = strpos($sentence,$search,$offset)) !==FALSE)
{
 echo $j.'. '.$pos.'<br>';
 $offset += $length;
 $j++;
}
?>

返回:

  
      
  1. 0
  2.   
  3. 3
  4.   
  5. 6
  6.   

拳头结果的显示证明是0,这是假的吗?为什么“while循环”中的代码操作完全相同?

1 个答案:

答案 0 :(得分:2)

  

拳头结果的显示证明为0,为FALSE

我认为你是误导,0是is第一次出现的位置而不是布尔值0

$sentence='is is is';
           ^  ^  ^
           0  3  6