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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 11:01:31 2024 UTC