[PHP] foreach loop to set variables

2008-04-25 Thread jamest

I am passing an array to a class which I want to take the array data and
create some variables from the array's keys and values.

So I want to create (in this case 21) new variables that I want to create in
the foreach but with no success.

foreach ($formdata as $key => $value) {
echo "$key = $value";
}

This echo's all the data how I would expect.  But taking the echo out to
have:

foreach ($formdata as $key => $value) {
$key = $value;
}

But this doesn't work. The variables aren't set.

I was thinking that I could set up the variables outside of the function by
using public $variablename for all the different variables then set the
variable value using:

foreach ($formdata as $key => $value) {
$this->key = $value;
}

But that didn't work either.
-- 
View this message in context: 
http://www.nabble.com/foreach-loop-to-set-variables-tp16895552p16895552.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] foreach loop to set variables

2008-04-25 Thread jamest

Thats perfect.  I didn't even know about this.

Stut wrote:
> 
> 
> $$key = $value;
> 
> They're called variable variables - search the manual for that term  
> for more info.
> 
> -Stut
> 
> -- 
> http://stut.net/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/foreach-loop-to-set-variables-tp16895552p16898164.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php