Wo0tHigh Posted February 19, 2008 Share Posted February 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
marcus Posted February 19, 2008 Share Posted February 19, 2008 $thing = array(); $thing[1]['name'] = "Dave"; $thing[2]['name'] = "Cheryl"; $thing[3]['name'] = "Marcus aka the best name"; for($i=1;$i<=3;$i++){ include_once "things/thing". $i .".php"; echo $thing[$i]['name'] . "<br>\n"; } que? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 19, 2008 Share Posted February 19, 2008 or a simpler way would be: $num='1'; while($num<'2'){ include_once'things/thing'.$num.'.php'; $varname = "thing".$num; $var = $$varname; echo'$var[name]<br />';//HERE $num++; } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 19, 2008 Share Posted February 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.