Re: Variable variables
| From: | Philip Olson | Date: | Wed, 26 Sep 2001 21:16:21 +0000 |
| Subject: | Re: Variable variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68922@lists.php.net to get a copy of this message | ||
If I'm reading your snippet correctly, then :
$foo = 'bar';
$bar = array('apple','banana');
print ${$foo}[0]; // apple
Note the use of {braces}. The last paragraph in the manual describes this
a bit :
http://www.php.net/manual/en/language.variables.variable.php
Although I don't see the point of $newvar as you're keeping track of $a in
the array itself. Looks like the below code will create a ton of
variables (arrays) each with one $a as the single key. Just using
$finalresult may be more appropriate, hard to say.
And some tips :
$arr[foo] will create an error/warning here, $arr['foo'] will not.
"$foo" isn't as pretty as $foo
regards,
Philip Olson
On Wed, 26 Sep 2001, Richard Baskett wrote:
> I can not figure out why this is not working!
>
> for ($j=0; $j<$resultNum; $j++) {
> $newvar = "finalresult".$a;
> $$newvar[$a][name] = $resultRow[name];
> $$newvar[$a][title] = $resultRow[title];
> $$newvar[$a][descript] = $resultRow[descript];
> $$newvar[$a][countkey] = substr_count("$resultRow[keywords]",
> "$keyword");
> a++;
> }
>
> This is how you use variable variables, is it not? Is it because it's a
> multidimensional array? or am I missing something else?
>
> Rick
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>