Re: Why is this array_walk_recursive action not working?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/24/2011 3:01 AM, Dave M G wrote:
> PHP users,
> 
> I obviously don't understand what array_walk_recursive does.
> 
> Can someone break down in simple terms why the following doesn't work?
> 
> - - -
> 
> $karamohOutput['test'] = "";
> 
> function test_print($item, $key)
> {
>     return "$key holds $item\n";
> }
> $karamohOutput['test'] .= array_walk_recursive($karamohArray, 'test_print');
> 
> - - -
> 
> Any advice would be much appreciated.
> 

if you read the following page description of the function, you will see that
the function returns a bool value.  Not the return statement of your custom
function call.

http://us.php.net/array_walk_recursive

If you read the Note under the funcname section, you will see that when you call
the function, it will pass the value as a reference, so, change around your
function like this.

$karamohOutput['test'] = "";

# notice this .....>|
function test_print(&$item, $key)
{
    $item = "$key holds $item\n";
}
array_walk_recursive($karamohArray, 'test_print');

print_r($karamohArray);

Give this a try and let us know.

Jim Lucas

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux