Re: Why is this array_walk_recursive action not working?

From: Date: Thu, 24 Feb 2011 16:25:34 +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-311563@lists.php.net to get a copy of this message
On 24 February 2011 15:15, 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 function changeName($name) { echo "My name is $name.\n"; $name = 'Simon'; echo "My name is $name.\n"; } $name = 'Richard'; echo "My name is $name.\n"; changeName($name); $name = 'Richard'; echo "My name is $name.\n"; ?> Read about variable scope at [1]. Richard. [1] http://docs.php.net/manual/en/language.variables.scope.php -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.general (#311563) next »