Re: [PHP] Global Arrays ?
> It may be a bug in your PHP - walking an array with each probably sets some > internal position marker which may be buggy for your very situation (global > variable in local function - something like that). Thanks for that. I tried it with foreach and it works now. Jason -- Hofstadter's Law : "It always takes longer than you expect, even when you take Hofstadter's Law into account." -- 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]
Re: [PHP] Global Arrays ?
The first thing that comes to mind - if you say it's working with local variables - is trying to set it local prior to using it (i.e. insert a "$loc_months=$g_months" just below "global $g_months" and use the local variable from then on). It may be a bug in your PHP - walking an array with each probably sets some internal position marker which may be buggy for your very situation (global variable in local function - something like that). Bogdan Jason Rennie wrote: > > Sounds quite odd - you may try an "echo(serialize($g_months))" in the > > function and see what you get... It may be that the code generating the > > option box has problems - this way you make sure $g_months is empty indeed. > > Thanks for that. IT appears to be a problem with the function itself, as > the array is full of stuff. > > I guess the next question is, what am i doing wrong here, that lets it > work with a local array but not a global one ? > > function html_option_months($selected_month) { > > global $g_months; > echo(serialize($g_months)); > $result = ""; > while (list($key, $val) = each($g_months)) { > $result .= html_option($key,$val, ($selected_month == $key)); > } > return $result; > } > > Jason > > -- > Hofstadter's Law : "It always takes longer than you expect, even when you > take Hofstadter's Law into account." > > -- > 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] -- 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]
Re: [PHP] Global Arrays ?
> Sounds quite odd - you may try an "echo(serialize($g_months))" in the > function and see what you get... It may be that the code generating the > option box has problems - this way you make sure $g_months is empty indeed. Thanks for that. IT appears to be a problem with the function itself, as the array is full of stuff. I guess the next question is, what am i doing wrong here, that lets it work with a local array but not a global one ? function html_option_months($selected_month) { global $g_months; echo(serialize($g_months)); $result = ""; while (list($key, $val) = each($g_months)) { $result .= html_option($key,$val, ($selected_month == $key)); } return $result; } Jason -- Hofstadter's Law : "It always takes longer than you expect, even when you take Hofstadter's Law into account." -- 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]
Re: [PHP] Global Arrays ?
Sounds quite odd - you may try an "echo(serialize($g_months))" in the function and see what you get... It may be that the code generating the option box has problems - this way you make sure $g_months is empty indeed. Bogdan Jason Rennie wrote: > Hi all, > > I've got an array in the global scope called $g_months which oddly enough > contains the names of the months. > > Now when I try to import this into a function as > > global $g_months; > > it doesn't work. When php prints out the array as an option box I just > wind up with no options. > > Any ideas why this is the case ? Am I doing something wrong ? -- 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]
[PHP] Global Arrays ?
Hi all, I've got an array in the global scope called $g_months which oddly enough contains the names of the months. Now when I try to import this into a function as global $g_months; it doesn't work. When php prints out the array as an option box I just wind up with no options. Any ideas why this is the case ? Am I doing something wrong ? Jason -- Hofstadter's Law : "It always takes longer than you expect, even when you take Hofstadter's Law into account." -- 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]