php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2980 array_walk behaves different than in php3
Submitted: 1999-12-15 13:41 UTC Modified: 1999-12-15 13:47 UTC
From: hholzgra at media-engineering dot de Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Latest CVS (15/12/1999) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hholzgra at media-engineering dot de
New email:
PHP Version: OS:

 

 [1999-12-15 13:41 UTC] hholzgra at media-engineering dot de
array_walk() PHP4 won't reset() the array before walking,
it will start at the current position instead of the
first element as php3 does

? is this a bug or a feature ?

if it is a feature, than the example
in the documentation has to be changed ...

<pre>
$fruits=array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");

function test_alter( &$item1, $key, $prefix ) {
  $item1 = "$prefix: $item1";
}

function test_print( $item2, $key ) {
  echo "$key. $item2<br>\n";
}

array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter', 'fruit' );
array_walk( $fruits, 'test_print' );
</pre>

will need a 'reset($fruits);' before call #2 and #3 
of array_walk to work

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-12-15 13:47 UTC] andrei at cvs dot php dot net
It's a feature. I've corrected the documentation.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC