Re: Why is this array_walk_recursive action not working?

From: Date: Thu, 24 Feb 2011 18:53:28 +0000
Subject: Re: Why is this array_walk_recursive action not working?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311572@lists.php.net to get a copy of this message
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

« previous php.general (#311572) next »