bdmovies Posted July 24, 2009 Share Posted July 24, 2009 $info is an array: <?php foreach($info as $key => $value) { $key = $value; echo "$key = ".$value . "<br/>"; } ?> This prints VALUE = VALUE, not KEY = VALUE. Why wouldn't the key get stored as the variable name? This particular array comes from a form with nearly several inputs, so I wanted to streamline the variable naming process by using the loop, what am I doing wrong? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 24, 2009 Share Posted July 24, 2009 that's because you're just assigning the value of $value to the variable $key. if you want to use $key as the variable name, you need to use variable variable notation: $$key = $value; however, the extract() function will do this for you. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted July 25, 2009 Author Share Posted July 25, 2009 Thanks very much, I knew I had seen a function that could do it, just couldn't remember. And I figured I was missing something simple, like the extra $. Thanks again. 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.