For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > July 2006 > variable variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author variable variables
Bundy

2006-07-29, 6:56 pm

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!
========================================
===================


Bundy

2006-07-29, 6:56 pm

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com