unidox Posted May 29, 2008 Share Posted May 29, 2008 Is there anyway to turn an array value into a variable. Like: array("1","2",); into: $1 $2 Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 29, 2008 Share Posted May 29, 2008 Answer to your question YES Quote Link to comment Share on other sites More sharing options...
unidox Posted May 29, 2008 Author Share Posted May 29, 2008 How would I do it? Quote Link to comment Share on other sites More sharing options...
trq Posted May 29, 2008 Share Posted May 29, 2008 Variables must start with letters or underscores (not numbers) for starters. Why do you think you need to do this? Quote Link to comment Share on other sites More sharing options...
unidox Posted May 30, 2008 Author Share Posted May 30, 2008 I have a function inside an object to process a form, and I want to type in an array and turn it into variables to process the sql and other checks. How can I turn an array into variables? Quote Link to comment Share on other sites More sharing options...
trq Posted May 30, 2008 Share Posted May 30, 2008 No idea if this will help, your description is still pretty unclear. <?php $a = 'foo'; $b = 'bar'; $x = array('a','b'); foreach ($x as $y) { echo $$y; } ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 30, 2008 Share Posted May 30, 2008 $arr = array('a','b','c'); foreach($arr as $v){ eval('$'.$v.' = "some value";'); } echo $a.'<br>'.$b.'<br>'.$c; Quote Link to comment 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.