|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-08 09:53 UTC] black at scene-si dot org
Description: ------------ replace key() with current() and you get the value with no problems, key() however doesnt work. the wierd part, sometimes the bellow code works, since i have 2 "identical" classes, one of which uses this method with key() - and makes correct results, however this short reproducable script doesnt. works: http://sunshine.krneki.org/files/halcyon/hal.phps doesnt: http://sunshine.krneki.org/files/halcyon/hal2.phps (search for 'reset', note that i have changed to use current in hal2.phps in the update function, so check out plot() which is still identical). cleaning up code is sometimes a b***h ;) Reproduce code: --------------- $data = array("foo","bar","x","y"); for (reset($data); $id=key($data); next($data)) { var_dump($id); } for (reset($data); $id=current($data); next($data)) { var_dump($id); } Expected result: ---------------- int(0) int(1) int(2) int(3) string(3) "foo" string(3) "bar" string(1) "x" string(1) "y" Actual result: -------------- string(3) "foo" string(3) "bar" string(1) "x" string(1) "y" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 01:00:01 2025 UTC |
<_Wez_> your for loop is equivalent to this: <_Wez_> reset($data); <_Wez_> while ($id = key($data)) { <_Wez_> var_dump($id); <_Wez_> next($data); <_Wez_> } <black|one> ... your point? <_Wez_> $id = key($data) ==> 0 on the first iteration <_Wez_> while (0) { <_Wez_> }