Last active
August 29, 2015 14:14
-
-
Save bootjp/1763c60d479f51757b38 to your computer and use it in GitHub Desktop.
PHP 5.5.14 foreach 内のポインタの挙動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = [ | |
'key' => 'value', | |
'key2' => 'value2', | |
'key3' => 'value3', | |
'key4' => 'value4', | |
'key5' => 'value5' | |
]; | |
foreach ($array as $key => $value) { | |
$tmp = current($array); // string(6) "value2" | |
var_dump($tmp); // string(6) "value2" | |
$tmp = next($array); // string(6) "value3" | |
$tmp = prev($array); // string...(略) | |
if (next($array) === false) { //次がなければreturn …ポインタずれてるやん? | |
return $value; // これだとポインタが2つ進んでるから… | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment