| Author |
variable variables
|
|
|
| I am why the the simple script using variable variables does
not work.
<?php
$test_array = array('one','two');
$x = 5;
foreach($test_array as $key => $value);
{
$variable = $value;
$$variable = $x;
$x++;
}
echo "First number is ".$one."<br>";
echo "Second number is ".$two."<br>";
?>
Outputs
First number is
Second number is 5
Instead of
First number is 5
Second number is 6
Your assistance will be appreciated.
Bundy
| |
| Marnok.com 2006-07-29, 6:56 pm |
|
"Bundy" <bigbadbundyREMOVETHIS@vfemail.net> wrote in message
news:44cbb127$0$23620$c3e8da3@news.astraweb.com...
>I am why the the simple script using variable variables does not
>work.
>
> <?php
>
> $test_array = array('one','two');
> $x = 5;
> foreach($test_array as $key => $value);
> {
> $variable = $value;
> $$variable = $x;
> $x++;
> }
>
> echo "First number is ".$one."<br>";
> echo "Second number is ".$two."<br>"; ?>
> Outputs
> First number is
> Second number is 5
>
>
> Instead of
> First number is 5
> Second number is 6
>
> Your assistance will be appreciated.
>
> Bundy
lose the semicolon at the end of the "foreach" statement.
--
http://www.marnok.com - if you liked this post, visit me at home!
========================================
===================
| |
|
| Marnok.com wrote:
> "Bundy" <bigbadbundyREMOVETHIS@vfemail.net> wrote in message
> news:44cbb127$0$23620$c3e8da3@news.astraweb.com...
>
>
> lose the semicolon at the end of the "foreach" statement.
>
>
Well spotted.
Thanks
Bundy
|
|
|
|