[PHP] Sizeof variable variable arrays
Hi there guys, Who's awake today then? :) What I'm trying to do is create variable variable arrays and then fill these arrays with values. The problem I have though is that the values don't appear to be getting stored - as following the assignment I have outputted a 'sizeof' command which always outputs 0. Here's a snippet of the code. Any ideas guys??? ... //store children page_IDs into array for each parent $str_array = menu_array_ . $current_parent_page_ID; $$str_array = array(); for ($child_cnt = 0; $child_cnt $number_children; $child_cnt++) { $db_help_structure-next_record(); //get page_ID value $page_ID = $db_help_structure-return_single_result('page_ID'); //$page_ID is now set echo storing in $str_array position $child_cnt: . $page_ID . br; $$str_array[$child_cnt] = $page_ID; echo size: . sizeof($$str_array) . br; } ... Email: [EMAIL PROTECTED] [EMAIL PROTECTED]
Re: [PHP] Sizeof variable variable arrays
On Friday 11 January 2002 20:02, Neil Freeman wrote: Hi there guys, Who's awake today then? :) Someone isn't :) Here's a snippet of the code. Any ideas guys??? ... //store children page_IDs into array for each parent $str_array = menu_array_ . $current_parent_page_ID; $$str_array = array(); for ($child_cnt = 0; $child_cnt $number_children; $child_cnt++) { $db_help_structure-next_record(); //get page_ID value $page_ID = $db_help_structure-return_single_result('page_ID'); //$page_ID is now set echo storing in $str_array position $child_cnt: . $page_ID . br; $$str_array[$child_cnt] = $page_ID; echo size: . sizeof($$str_array) . br; } You need to resolve the ambiguity in your code by placing braces around the variable part of the variable variable (!) ie: ${$str_array}[$child_cnt] = $page_ID; See manual for details. See the annotated online manual for more examples. hth -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Go out and tell a lie that will make the whole family proud of you. -- Cadmus, to Pentheus, in The Bacchae by Euripides */ -- 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] Sizeof variable variable arrays
That's done the trick. More coffee for me I think :) Cheers Jason. Jason Wong wrote: On Friday 11 January 2002 20:02, Neil Freeman wrote: Hi there guys, Who's awake today then? :) Someone isn't :) Here's a snippet of the code. Any ideas guys??? ... //store children page_IDs into array for each parent $str_array = menu_array_ . $current_parent_page_ID; $$str_array = array(); for ($child_cnt = 0; $child_cnt $number_children; $child_cnt++) { $db_help_structure-next_record(); //get page_ID value $page_ID = $db_help_structure-return_single_result('page_ID'); //$page_ID is now set echo storing in $str_array position $child_cnt: . $page_ID . br; $$str_array[$child_cnt] = $page_ID; echo size: . sizeof($$str_array) . br; } You need to resolve the ambiguity in your code by placing braces around the variable part of the variable variable (!) ie: ${$str_array}[$child_cnt] = $page_ID; See manual for details. See the annotated online manual for more examples. hth -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Go out and tell a lie that will make the whole family proud of you. -- Cadmus, to Pentheus, in The Bacchae by Euripides */ -- 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] *** This message was virus checked with: SAVI 3.52 last updated 17th December 2001 *** -- Email: [EMAIL PROTECTED] [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] Sizeof variable variable arrays
-Original Message- From: Neil Freeman [mailto:[EMAIL PROTECTED]] Sent: 11 January 2002 12:03 Who's awake today then? :) What I'm trying to do is create variable variable arrays and then fill these arrays with values. The problem I have though is that the values don't appear to be getting stored - as following the assignment I have outputted a 'sizeof' command which always outputs 0. Once again, I can't help wondering why go all round the houses with $$ instead of using arrays -- in this case, 2-dimensional ones (arrays of arrays!): Here's a snippet of the code. Any ideas guys??? ... //store children page_IDs into array for each parent $str_array = menu_array_ . $current_parent_page_ID; $$str_array = array(); $str_array = array(); $str_array[$current_parent_page_ID] = array(); for ($child_cnt = 0; $child_cnt $number_children; $child_cnt++) { $db_help_structure-next_record(); //get page_ID value $page_ID = $db_help_structure-return_single_result('page_ID'); //$page_ID is now set echo storing in $str_array position $child_cnt: . $page_ID . br; $$str_array[$child_cnt] = $page_ID; $str_array[$current_parent_page_ID][$child_cnt] = $page_ID; echo size: . sizeof($$str_array) . br; } ... Mind you, I've done no comparison of the relevant efficiencies of the $$ method and the 2-dimensional array -- I just find the arrays easier to comprehend (and less prone to syntactical problems!!). Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- 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]