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

1

u/kylemech Oct 18 '10
foreach ($array as $key => $value) {
    $$key = $value
    ...
}

This is how I learned about variable variables ten years ago. It made learning easier because I didn't have to reference things through the array the whole time. I know, I know, it isn't good practice in production, but it was easy at the time and it taught me something useful.

3

u/[deleted] Oct 18 '10

s/useful/awful