Re: Array key names - can they be called as strings?
| From: | Evan Nemerson | Date: | Thu, 17 Jul 2003 21:50:26 +0000 |
| Subject: | Re: Array key names - can they be called as strings? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155689@lists.php.net to get a copy of this message | ||
I kinda skimmed, but I think what you want is
foreach ( array_keys($SAVEVARS) as $key )
$query = "update table set $key=$SAVEVARS[$key];";
On Thursday 17 July 2003 02:38 pm, Mike Morton wrote:
> Perhaps I was not that clear on the subject :)
>
> I have the following array:
>
> $SAVEVARS[headerimage]=$_POST[headerimage];
> $SAVEVARS[backgroundimage]=$_POST[backgroundimage];
>
> I want to iterate through it to save to a database config:
>
> Forach($SAVEVARS as $whatever) {
> $query="update table set $whatever=$whatever[$whatever]";
> }
>
> Where the 'set $whatever' would become 'set headerimage' and
> '=$whatever[$whatever]' would become the value that was posted through and
> set on the line above.
>
> The question is the - the assigned string key - is there a way to retrieve
> that in a loop? Foreach, for, while or otherwise?
--
"Humanity's first sin was faith; the first virtue was doubt."
-Unknown