|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1999-12-10 21:00 UTC] fvkuipers at home dot com
[1999-12-10 23:12 UTC] andrei at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
This example is taken from the php3 documentation, and works in php3: $fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"); function test_alter( &$item1 ) { $item1 = 'bogus'; } function test_print( $item2 ) { echo "$item2<br>\n"; } array_walk( $fruits, 'test_print' ); array_walk( $fruits, 'test_alter' ); array_walk( $fruits, 'test_print' ); When I run this, I get the following and NOTHING else: lemon<br> orange<br> banana<br> apple<br> It seems that the array is traversed the first time, but not the next two times... perhaps it needs to restore the array pointer?? See the modification to this code: // The functions 'test_print' and 'test_alter' are as defined above... // [snip] array_walk( $fruits, 'test_print' ); reset($fruits); array_walk( $fruits, 'test_alter' ); reset($fruits); array_walk( $fruits, 'test_print' ); This produces the expected output of: lemon<br> orange<br> banana<br> apple<br> bogus<br> bogus<br> bogus<br> bogus<br> This is the result of the first file I've worked on under php4... so there may be more bugs on the way! HTH. Fred