|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-01 01:17 UTC] helly@php.net
[2004-10-01 01:50 UTC] oliver at burtchen dot com
[2006-01-01 21:54 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
Description: ------------ it looks loke array_key_exists() makes a copy of the given array if there is a reference to that array. if there is no reference, everything works well. Reproduce code: --------------- // just to get the time in microseconds function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $cnt = 2000; $a = array_fill(0, $cnt, 'foo'); // this works as aspected very fast $mtime = getmicrotime(); for ($i = 0; $cnt > $i; $i++) array_key_exists($i, $a); echo getmicrotime() - $mtime . '<br>'; $b =& $a; // making a reference, but not using it // this will take a huge amount of time, but it's the same code as above $mtime = getmicrotime(); for ($i = 0; $cnt > $i; $i++) array_key_exists($i, $a); echo getmicrotime() - $mtime . '<br>'; Expected result: ---------------- the two loops should work the same.