Jump to content

Print VALUE of variable, not variable name?


kernelgpf

Recommended Posts

[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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.