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);
}

--
Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



-- 
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