|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-13 14:48 UTC] samuel dot roze at gmail dot com
Description:
------------
The keys of arrays should be accessible by reference into walking functions. See the scripts below:
Test script:
---------------
$array = array(
'COL1' => 'VALue1',
'COL2' => '2',
'COL4' => 'valUE3'
);
var_dump($array);
$walk = array_walk($array, function (&$value, &$key) {
$key = strtolower($key);
$value = strtolower($value);
});
var_dump($walk, $array);
Expected result:
----------------
array
'COL1' => string 'VALue1' (length=6)
'COL2' => string '2' (length=1)
'COL4' => string 'valUE3' (length=6)
boolean true
array
'col1' => string 'value1' (length=6)
'col2' => string '2' (length=1)
'col4' => string 'value3' (length=6)
Actual result:
--------------
array
'COL1' => string 'VALue1' (length=6)
'COL2' => string '2' (length=1)
'COL4' => string 'valUE3' (length=6)
boolean true
array
'COL1' => string 'value1' (length=6)
'COL2' => string '2' (length=1)
'COL4' => string 'value3' (length=6)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
Array keys are not proper PHP values, so this is not possible. There is no reasonable way to handle a callback function that did: function (&$value, &$key) { $key = function () {}; //or $key = array(); }