php - Why is this code an infinite loop? -
before completing code, tested mistake , realized not stop:
$var = "any"; ($i=1; $i < 2; $i++){ $var.$i = "any"; }
why produce infinite loop? , why doesn't php produce error?
i did simple test :
echo $i; $var.$i = "any"; var_dump($var);
result :
1string(3) "any" anzstring(3) "any"
so $i transformed "anz" , doesn't pass validation out of loop.
$var.$i = "any"; not correct, don't know trying do, if want fill , array should more :
$var = array(); ($i=1; $i < 2; $i++){ $var[] = "any"; }
if want change string letter letter :
$var = "any"; ($i=1; $i < 2; $i++){ $var[$i] = "a"; // asign new letter string @ $i position }
Comments
Post a Comment