Jump to content

WILL NOT SPAM BOARD. (LAST question) - producing variables from variables


DamienRoche

Recommended Posts

I have one last problem, and I swear I won't spam the board. Very sorry I didn't put this in a reply, but I was so excited I sorted something out I just pressed the 'topic solved' link.

 

The loop:

 

$loop = 1;
$limit = 3;
$Y = 0;
$N = 0;
while ($loop <= $limit){

$fb = "\$e".$loop."fname";
$sb = "\$e".$loop."sname";
$pb = "\$e".$loop."passport";
$cb = "\$e".$loop."check";

echo "fb:$fb<br>sb:$sb<br>pb:$pb<br>cb:$cb<br>";

if($cb!=""){
if($fb!="" && $sb!="" && $pb!=""){
$Y = $Y + 1;}else{$N = $N + 1;}
}
$loop = $loop +1;
}

 

Output for one loop of the echo:

 

fb:$e1fname

sb:$e1sname

pb:$e1passport

cb:$e1check

 

The variables within the variables I am creating ($fb,$sb etc.) are not acting as variables. I can see when I echo them that they are outputting text and not functioning php.

 

Do you have any idea why? How do I construct these variables so when I call the variable that constructed them, they call the variable constructed and not a bunch of text...BREATHE...

 

Last question. Any help much appreciated.

Thanks ProjectFear!- you have been a saint tonight.

 

Sadly, removing the \ didn't work because then the 'e' turned into a variable itself. Evals would of seeded even more questions. I did, however, find a solution so will post here just in case.

 


$loop = 1;
$fb = ${"e".$loop."fname"};

///this makes the variable $fb return a new variable $e1fname

 

Thanks again PF for all your help.

 

 

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.