Jump to content

Help! Variables within variables


Wo0tHigh

Recommended Posts

Ok so!

 

in a file called "thing1.php" I have the following...

 

<?php
$thing1['name']="Dave";
?>

 

Then in another page I have this...

 

$num='1';
while($num<'2'){
include_once'things/thing'.$num.'.php';	
echo'$thing$num[name]<br />';//HERE
$num++;
}

 

As you can see from the above, where it says HERE, this is where the problem is! I need to display $thing1[name], 1 being retrevied from a variable. Any ideas how?

 

Thank you very much! Dan

Link to comment
https://forums.phpfreaks.com/topic/91804-help-variables-within-variables/
Share on other sites

The problem is here

<?php
echo'$var[name]<br />';//HERE
?>

 

Variables contained in strings delimited by single quotes are not expanded. You would want to do something like

<?php
echo $var[name] . '<br />';//HERE
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.