1

Possible Duplicate:
variable variables

once I have established the first empty input field I then want to give it the value of $_POST['email']; by making the value of $key into a variable but how can I make the value of a variable into a new variable (if you see what I mean) I will try to demonstrate what I mean below:

$email = $_POST['email'];
      foreach( $_POST as $key=> $for ) {
               if($for=="") { 

        //     $ + the value of ($key) = $email;           
                  break;
                }
         }

email: <input name="email">

    a: <input type="text" name="a" value='<?php echo $a; ?>'>
    b: <input type="text" name="b" value='<?php echo $b; ?>'>
    c: <input type="text" name="c" value='<?php echo $c; ?>'>
       <input type="submit">
Community
  • 1
  • 1
user1559811
  • 437
  • 3
  • 10
  • 26
  • 6
    Exactly as you described it: `$$key`. They're called [variable variables](http://php.net/manual/en/language.variables.variable.php). – Joseph Silber Jan 21 '13 at 02:23
  • I can't believe it was so simple I feel foolish. Thanks very much, now I know – user1559811 Jan 21 '13 at 02:26
  • 1
    Why not just stick with the `$_POST` array with its keys? Variable variables pollute the current scope – Phil Jan 21 '13 at 02:45

1 Answers1

2

Use $$key = $email into the foreach, it'll make a new variable with the variable $key value and assign $email value to it.

Felipe Francisco
  • 1,064
  • 2
  • 21
  • 45