Hey-

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.

In other words

//Define GLOBAL
$array_test = array();

switch(){
BLAH
BLAH

}

function main() {
global $array_test;
BLAH
BLAH

}

function test_one(){
global $array_test;
BLAH
BLAH

}


Hope that helps.

Henrik

On Sunday 28 October 2001 15:17, Imar de Vries wrote:
>  Hi all,
>
>  a very frustrating problem. For some reason I am not able to pass on an
>  array between two functions, although I declare it global in both of
>  them. I suspect my use of a switch statement to control the flow of the
>  functions is causing some trouble, but I'm not sure. Changing the order
>  in which I declare the array global did not help, nor the use of
>  $GLOBALS.
>
>  This is a simple representation of what I do:
>
>  switch ($action) {
>   default:
>   main();
>   break;
>   case "test_one":
>   test_one();
>   break;
>  }
>
>  // -------------------------------------------
>
>  function main() {
>
>   $array_test = array();
>   global $array_test;
>
>   $array_test[0] = "First array, first element";
>   $array_test[1] = "First array, second element";
>
>   print("Content of first array in the main function is now:<br>");
>   var_dump($array_test);
>
>   print ("<p><form method=\"post\" action=\"arraytest.php\"
>  enctype=\"multipart/form-data\">");
>   ?>
>   <input type="hidden" name="action" value="test_one">
>   <input type="submit" value="Test" tabindex="6">
>   </form>
>   <?
>  }
>
>  // -------------------------------------------
>
>  function test_one() {
>
>   global $array_test;
>
>  // This results in NULL
>
>   print("Content of first array in the first test function is now:<br>");
>
>   var_dump($array_test);
>
>   $array_test[2] = "First array, third element";
>   $array_test[3] = "First array, fourth element";
>
>  // This results in the third and fourth element being shown
>
>   print("<p>After addition, content of first array is:<br>");
>   var_dump($array_test);
>  }

-- 

Henrik Hudson
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to