Using STRING as an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Using STRING as an array

Post by mbaroz »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi There
I have saved a list of VarNames in  my database that are presented as strings  "SITE[name]" ....
I would like to use it and assign it as it was a variable.

Code: Select all

<?php
$SITE[name]="value";
?>
i used the ${$DBVARNAME}="value";
but no success

Please help

Thanks
Moshe Bar-oz


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll have to break apart the name so you can get the actual variable name, "SITE," and the index inside of it, "name," and them create the variable like so:

Code: Select all

${$varName}[$index] = $value;
Post Reply