kernelgpf Posted January 2, 2007 Share Posted January 2, 2007 [code]$space='$row[space';$space.="$i]";$space="$space";$spacepic='$row[space';$spacepic.="$i";$spacepic.='pic]';$spacepic="$spacepic";[/code]Basically, this code is running in a for loop, and $i is the incremented number.. the possible variables are space1, space2, space3, etc. etc. up until 9, and I've got it to add the $i in, but now when I ask it to print, it's printing the variable name, not the value, because I had to put single quotes around the $i else it would cause a parse error. Quote Link to comment https://forums.phpfreaks.com/topic/32612-print-value-of-variable-not-variable-name/ Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Sorry, but that code makes no sense. Post your loop and maybe we can see what your trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/32612-print-value-of-variable-not-variable-name/#findComment-151688 Share on other sites More sharing options...
sasa Posted January 2, 2007 Share Posted January 2, 2007 try[code]<?php$row=array('space1'=>11,'space2'=>12,'space1pic'=>21,'space2pic'=>22);for ($i=1;$i<3;$i++) { $a = 'space'.$i; echo $row[$a]; echo "<br />\n"; // or echo $row['space'.$i.'pic']; echo "<br />\n";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32612-print-value-of-variable-not-variable-name/#findComment-151692 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.