r/programming • • Oct 18 '10

Today I learned about PHP variable variables; "variable variable takes the value of a variable and treats that as the name of a variable". Also, variable.

http://il2.php.net/language.variables.variable
591 Upvotes

781 comments sorted by

View all comments

Show parent comment

1

u/hattmall Oct 19 '10

Making a webpage. I have a foreach for an XML, of picture urls. I have $i in the foreach that i'm increasing by 1 foreach item. I'm making a javascript that scrolls the images, so I need to id each image, in a list. So i'm assigning variables like this $pic$i and then putting them in the list later.

I haven't actually done it yet, there may be a better way, but it's exactly what I was wondering, if there was somehow I could use my number in $i as a variable name.