Re: Why is this array_walk_recursive action not working?
| From: | FeIn | Date: | Thu, 24 Feb 2011 16:15:51 +0000 |
| Subject: | Re: Why is this array_walk_recursive action not working? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311562@lists.php.net to get a copy of this message | ||
Hi,
Well, first array_walk_recursive returns a boolean so what you are doing in
you script is append a boolean (true or false) that will be converted to
string. So if array_walk_recursive will return true you will have the string
"1" in $karamohOutput['test'], and if array_walk_recursive will return false
you will have the empty string "" in $karamohOutput['test'].
I think what you're after is this:
$karamohOutput['test'] = "";
foreach ( new RecursiveIteratorIterator( new RecursiveArrayIterator(
$karamohArray ) ) as $key => $item ) {
$karamohOutput['test'] .= "$key holds $item\n";
}
On Thu, Feb 24, 2011 at 5:15 PM, Dave M G <martin@autotelic.com> wrote:
> FeIn,
>
> Thank you for responding.
>
>
> > what did you expect to happen when you call array_walk_recursive?
>
>
> What I don't understand is why it did not append to the string as it
> walked through each key/value pair.
>
> It seems like even though the variable inside the function called by
> array_walk_recursive has the same name as a global variable, it gets
> treated as if it only has local scope and nothing done to it applies to
> the global variable.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>