Forum Moderators: coopster

Message Too Old, No Replies

Using Curly Braces and Variable Variables

         

Habtom

6:17 am on May 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

for ($i=0; $i <10; $i++) {
$image{$i} = $value[$y];
}

Shouldn't this give me the values for $image0, $image1 . . . .etc

Habtom

TomAnthony

10:19 am on May 8, 2006 (gmt 0)

10+ Year Member



$image{$i} = $value[$y];

Why one set of {}s and one of []s?

Your line should read:

$image[$i] = $value[$y];

I'd imagine you are getting a fatal error.

Also, do you meean to access $y index of $value rather than $i?

Habtom

5:30 pm on May 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not getting a fatal error just no output.

Shouldn't this give me the values for $image0, $image1 . . . .$image6?

Hab

siMKin

7:31 pm on May 8, 2006 (gmt 0)

10+ Year Member



"$image0, $image1 . . . .$image6?"

That's not the way to go. Better put them in an array, it's about 100x easier to work with.
So

$image[0], $image[1] .... $image[6]

or
$image = array( 
0 => "whatever the value should be",
1 => "whatever the value should be",
6 => "whatever the value should be"
);

jatar_k

8:03 pm on May 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for ($i=0; $i <10; $i++) {
$image{$i} = $value[$y];
}

what you have there gives no actual output so I am not sure what output you are looking for.

if you wanted to assign values from an array called $value to vars in the form of $image0 to $image9 then you would need to do it this way

for ($i=0; $i <10; $i++) {
${'image' . $i} = $value[$y];
}