|
Posted by Johnny on 09/26/06 19:46
"Charles O'Flynn" <charles@matchwalk.com> wrote in message
news:12hivk1109pj1e0@corp.supernews.com...
> As a complete newcomer (2-3 days) to PHP, although not to programming in
> general, I have 'dived in' to start a small project to read and parse an
XML
> data stream. I have already worked out most of the more specialist
aspects
> of the job but am now completely stuck on something I would have thought
> were simplicity itself...
> I need to have a large number of global variables visible inside
functions -
> it's not possible to pass them into the functions themselves, since
although
> they are user functions, the parameter type/count is fixed. Reading what
> information I can find, I was under the impression that variables declared
> at the head of the PHP block as 'global' would be visible inside all
> functions. My problem is this: yes, it appears I can assign values to
> these global variables inside a function, (I think), but immediately I
exit
> the function, the data is lost. At first sight, I could be assigning
values
> to variables with identical names but local scope within the functions,
but
> when I performed an 'explode()' inside a function, assigning the result to
> one of my 'global' variables and then, on exiting the function, tried to
> 'echo' the result, the result was 'ARRAY' - the original global variable
had
> presumably been converted, since it started life as a scalar.
> I don't really want to go to superglobals unless I have to - can anybody
> please tell me where I'm going so obviously wrong and how I can correct
it?
> This is such a basic problem, I can't help thinking everybody must know
the
> answer...
> Thanks for any help/advice offered.
>
>
just need to use the global keyword when inside the function, it's explained
here:
http://us3.php.net/global
Navigation:
[Reply to this message]
|