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:[EMAIL PROTECTED]]
Sent: 16 March 2001 00:15
To: [EMAIL PROTECTED]
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: [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]

Reply via email to