Jump to content

[SOLVED] Simple For loop with variable eval() issue.... please help.


shlomikalfa

Recommended Posts

hey,

i am trying to create a loop 1 to 5, that will compare two variables, one of them is easy since it's a global and i can use the brackets. but the other one doesn't have it... what should i do ?!

 

for ($i = 1; $i <6; $i++){
	echo $MyGlobalVar['VarID'.$i]."<br />";
	echo eval('$Var'.$i.'_ByID')."<br />";
}

 

Thanks in advance.

@flyhoney

I don't see what isn't understood in my question... i was just wanting to know how will i make that work... seems quit an explained to me...

 

$MyGlobalVar['VarID1'] = "My name is here";
$MyGlobalVar['VarID2'] = "2nd Name";
$MyGlobalVar['VarID3'] = "3rd thing";
$MyGlobalVar['VarID4'] = "4th.";
$MyGlobalVar['VarID5'] = "5th.";
$Var1_ByID = "This is something too";
$Var2_ByID = "This is something too2";
$Var3_ByID = "This is something too3";
$Var4_ByID = "This is something too3";
$Var5_ByID = "This is something too1212123";

   for ($i = 1; $i <6; $i++){
      echo $MyGlobalVar['VarID'.$i]."<br />";
      echo eval('$Var'.$i.'_ByID')."<br />";
   }
</code]

I think this should echo all of the variables.... but it does echo only the fist echo... the 2nd one launches a warning....
hope it's better understood..... 

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.