felito Posted June 13, 2011 Share Posted June 13, 2011 hi what is the problem of this php? $i=0; while ($sql -> fetch()) { $num.$i++ = $form[$val]; // error here echo ($num0); } i want something like: $num0 =$form[$val]; $num1 =$form[$val]; $num2 =$form[$val]; ... thanks Quote Link to comment https://forums.phpfreaks.com/topic/239183-syntax-problem/ Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 I doubt seriously this is the best way to handle whatever it is that you are trying to do, however it can be accomplished. $i=0; while ($sql -> fetch()) { $name = 'num' . $i++; $$name = $form[$val]; } // now you'll have variables $num0... x for ($x = 0; $x echo '$num'.$x . ' = ' . ${'num'.$x} . ' '; } Quote Link to comment https://forums.phpfreaks.com/topic/239183-syntax-problem/#findComment-1229403 Share on other sites More sharing options...
ManiacDan Posted June 14, 2011 Share Posted June 14, 2011 You're looking for arrays -Dan Quote Link to comment https://forums.phpfreaks.com/topic/239183-syntax-problem/#findComment-1229693 Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 You're looking for arrays -Dan Probably. Something like this: $vals = array(); while ($sql -> fetch()) { $vals[] = $form[$val]; } var_dump($vals); Quote Link to comment https://forums.phpfreaks.com/topic/239183-syntax-problem/#findComment-1229701 Share on other sites More sharing options...
ManiacDan Posted June 15, 2011 Share Posted June 15, 2011 Don't ever use variable variables unless you're absolutely certain there's no other way to go about doing things. If you ever have variables with sequential numbers at the end, you've done it wrong. The Array construct is perfect for what you're trying to do. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/239183-syntax-problem/#findComment-1230038 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.