Re: creating array on variable variable (bug?)
| From: | Tobias Talltorp | Date: | Fri, 16 Mar 2001 00:45:55 +0000 |
| Subject: | Re: creating array on variable variable (bug?) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44180@lists.php.net to get a copy of this message | ||
Thanks a million man!
This did the trick...
Best Regards,
// Tobias Talltorp
""Mahmoud Abu-Wardeh"" <mahmoud@infoscience.ltd.uk> wrote in message
news:IBEPJFAKLHILHMLAJGKDAEFPCDAA.mahmoud@infoscience.ltd.uk...
> try this: (you need to escape the variable part of the variable variable
> with {})
>
> <?php
> $name = "talltorp";
>
> $$name = array(1,2,3,4); // <-- this works
>
> for ($i=0; $i<10; $i++) { //
> ${$name}[] = $i; // <-- this will work now
> } //
>
> for ($i=0; $i<sizeof($talltorp); $i++){
>
> echo $talltorp[$i];
> }
> ?>
>
> -----Original Message-----
> From: Tobias Talltorp [mailto:tobias@talltorp.com]
> Sent: 16 March 2001 00:15
> To: php-general@lists.php.net
> Subject: [PHP] creating array on variable variable (bug?)
>
>
> Hello all.
>
> Howcome I can create an array on a variable variable using array(), but
not
> in a for-loop (See code below)?
>
> <?
> $name = "talltorp";
>
> $$name = array(1,2,3,4); // <-- this works
>
> for ($i=0; $i<10; $i++) { //
> $$name[] = $i; // <-- this does not work
> } //
>
> for ($i=0; $i<sizeof($talltorp); $i++)
>
> echo $talltorp[$i];
> }
> ?>
>
> In the for-loop I get this error message:
> Fatal error: Cannot use [] for reading in
> E:\Inetpub\wwwroot\testscript\sessions\test4.php on line 6
>
> Is this a bug or do I have the bugs in my head finally gotten to my
thinking
> area?
>
> Thanks,
> // Tobias Talltorp
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>