php - Variable assignment resets internal array pointer -
i have php code:
$a=array(1, 2, 3); var_dump(current($a)); each($a); each($a); each($a); var_dump(current($a)); $b=$a; var_dump(current($a)); the output "int(1) bool(false) int(1)" expect "int(1) bool(false) bool(false)", because after 3 times each internal pointer of $a should after end of array , stay there.
but apparently assignment $b=$a sets pointer of $a first element again. going on here?
(if remove 1 each, output "int(1) int(3) int(3)" expected.)
from http://php.net/manual/en/function.each.php:
caution: because assigning array variable resets original array's pointer, our example above cause endless loop had assigned $fruit variable inside loop.
Comments
Post a Comment