scarhand Posted December 4, 2007 Share Posted December 4, 2007 <?php while ($row = mysql_fetch_array($sql)) { $orig_{$row["name"]} = $row["value"]; } echo "orig_name = $orig_name"; any help is appreciated Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/ Share on other sites More sharing options...
kenrbnsn Posted December 4, 2007 Share Posted December 4, 2007 It should be working. You're just echoing the wrong variable. try: <?php while ($row = mysql_fetch_array($sql)) { $orig_{$row["name"]} = $row["value"]; } echo 'orig_name = ' . $orig_{$row['name']; ?> Ken Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406369 Share on other sites More sharing options...
scarhand Posted December 4, 2007 Author Share Posted December 4, 2007 well lets say that $row['name'] is = 'username' im trying to get the variable to become $orig_username Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406420 Share on other sites More sharing options...
revraz Posted December 4, 2007 Share Posted December 4, 2007 Which variable? Instead of echoing it, just turn it into a variable. $variable = "orig_name = " . $orig_{$row['name']; Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406424 Share on other sites More sharing options...
teng84 Posted December 4, 2007 Share Posted December 4, 2007 $x['test'] ='teng'; ${'orig_'.$x['test']} = 'i love php'; echo $orig_teng;// echo i love php that works... try Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406425 Share on other sites More sharing options...
teng84 Posted December 4, 2007 Share Posted December 4, 2007 IMO the reason why the above code wont work is that we cant concatenate the existing name of var eg.. $x.'tra'; to become $xtra and that should be ${'xtra'}; or ${$var.'value'} Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406428 Share on other sites More sharing options...
scarhand Posted December 4, 2007 Author Share Posted December 4, 2007 thanks teng Link to comment https://forums.phpfreaks.com/topic/80177-solved-why-wont-this-variable-declaration-work/#findComment-406467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.