Created
March 21, 2014 08:00
-
-
Save ksomemo/9681650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$ary = range(1, 100000); | |
reset($ary); | |
echo "array create end\n"; | |
echo memory_get_usage() .PHP_EOL; | |
echo "while start\n"; | |
while (list($key, $value) = each($ary)) { | |
if ($key === 0) echo memory_get_usage() .PHP_EOL; | |
} | |
echo memory_get_usage() .PHP_EOL; | |
echo "while end\n"; | |
echo "---------------\n"; | |
reset($ary); | |
echo memory_get_usage() .PHP_EOL; | |
echo "foreach start\n"; | |
foreach ($ary as $key => $value) { | |
if ($key === 0) echo memory_get_usage() .PHP_EOL; | |
} | |
echo memory_get_usage() .PHP_EOL; | |
echo "foreach end\n"; | |
Author
ksomemo
commented
Mar 21, 2014
- ループに入ってから1回目のメモリ使用量が変わってないのでforeach でよさそう
- foreach 後にメモリ使用量が戻らないのは$key, $valueが残っているからだと思う
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment