|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-06 14:04 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
[2016-08-06 14:04 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 13:00:01 2025 UTC |
Description: ------------ reset() work much slower than foreach() under PHP7 Looks like developers optimized foreach(), but forgot about reset(). Under PHP5 speeds are similar. Test script: --------------- $arr = array_fill(0, 10000, "a"); $ts = microtime(true); $first_key = -1; foreach ($arr as $k => $v) { $arr2 = $arr; reset($arr2); $first_key = key($arr2); } echo microtime(true)-$ts, "<br />\n"; echo $first_key, "<br />\n"; $ts = microtime(true); $first_key = -1; foreach ($arr as $k => $v) { $arr2 = $arr; foreach ($arr2 as $k2 => $v2) break; $first_key = $k2; } echo microtime(true)-$ts, "<br />\n"; echo $first_key, "<br />\n"; Expected result: ---------------- 0.0011060237884521 0 0.0011060237884521 0 Actual result: -------------- 0.64054489135742 0 0.0011060237884521 0