I'm trying to understand this code :
$array = [0, 1, 2];
foreach ($array as &$val) {
var_dump(current($array));
}
In PHP 5.6 the result would be int(1) int(2) bool(false)
, in PHP 7 the result would be int(0) int(0) int(0)
. The question is why?
Why isn't the result in both cases the values of the array 0, 1, 2
? I understand that current()
in PHP returns the current value, so each time the foreach goes over each one, isn't the current value that should be printed out?