Re: switch-statement overrides use of global arrays?
| From: | Henrik Hudson | Date: | Sun, 28 Oct 2001 22:17:33 +0000 |
| Subject: | Re: switch-statement overrides use of global arrays? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72644@lists.php.net to get a copy of this message | ||
Well, the switch statement will only run ONE of the functions, never both.
The default runs and then you break out of the switch, also: shouldn't
default be at the bottom of the switch? or is that just convention? Anyways,
there is no way for main() to ever "pass" anything to test_one(), since only
one or the other is called in the switch (unless your switch is in a loop and
$action changes in that loop).
Oh, your passing it back in via a form and then telling it to use: test_one.
Oh, ummm, everytime you submit the code you are calling a new "instance" of
the script. It will never remember variables between instances unless they
are passed to the script via POST and hidden fields. At least as far as I
know...but I might be missing something.
I would try and do whatever you are trying to do without resorting to a
resubmit or just pass the variable to the function inside main:
test_one($array_global);
Sorry I couldn't be of more help.
On Sunday 28 October 2001 15:48, you wrote:
> Hi Henrik,
>
> > I would think you would need to define $array_test outside in a "global"
> > environment rather then inside the function since I think/thought it
> > will just stay scoped in there and that "global" was used to access
> > variables which weren't defined inside a functions scope and make it
> > look outside.
>
> Yes, the only way I could avoid errors that occurred when I tried to
> manipulate the array, was to add a $array_test = array(); a few lines
> before the switch statement. Alas, this also emptied the array each time I
> went from one function to another via the switch statement.
>
> I guess I am trying something that is just not possible (when I insist on
> using the switch statement)?
--
Henrik Hudson
lists@rhavenn.net