以变​​量名增加数字

Background

I have a for loop creating a table of inputs for an html form:

for ($i = 1; $i <= $x; $i++) {
  echo '<select name="waldo_'.$i.'" id="waldo_'.$i.'">
      <option value="">...</option>
      <option value="foo">Foo</option>
      <option value="bar">Bar</option>
    </select>
    <label for="foo_'.$i.'">Foo '.$i.'</label>
    <input id="foo_'.$i.'" type="text" value="" name="foo_'.$i.'">
    <label for="bar_'.$i.'">Bar '.$i.'</label>
    <input id="bar_'.$i.'" type="text" value="" name="bar_'.$i.'">';
}

On submit, this populates a database.

Problem

Each submission needs to be editable. When I return to the form (as an admin) I need to see everything that was stored in the database by a particular user.

for ($i = 1; $i <= $x; $i++) {
  echo '<select name="waldo_'.$i.'" id="waldo_'.$i.'">
      <option value="">...</option>
      <option value="foo"';
  if($row['waldo_'.$i] == "foo") echo " selected='selected'";
  echo '>Foo</option>
      <option value="bar"';
  if($row['waldo_'.$i] == "bar") echo " selected='selected'"; 
  echo '>Bar</option>
    </select>
    <label for="foo_'.$i.'">Foo '.$i.'</label>
    <input id="foo_'.$i.'" type="text" value="'./*...*/.'" name="foo_'.$i.'">
    <label for="bar_'.$i.'">Bar '.$i.'</label>
    <input id="bar_'.$i.'" type="text" value="'./*...*/.'" name="bar_'.$i.'">';
}

My select properly "selects" the correct option, but I don't seem to be able to populate the text input values in a similar manner.
Somehow I need to echo the content in $foo_1, $foo_2, $foo_3, ..., $foo_x.

I have tried using $foo_.$i but that doesn't seem to work.

Is there a simple solution to this problem? Or is there a better method to format everything?

If I'm not misunderstanding your question:

$_POST["foo_".$i]

Should show you the submitted data.

EDIT: Or maybe this is what you are looking for?

for ($i = 1; $i <= $x; $i++) {
  echo '<select name="waldo_'.$i.'" id="waldo_'.$i.'">
      <option value="">...</option>
      <option value="foo"';
  if(isset($row['waldo_'.$i]) && $row['waldo_'.$i] == "foo") echo " selected='selected'";
  echo '>Foo</option>
      <option value="bar"';
  if(isset($row['waldo_'.$i]) && $row['waldo_'.$i] == "bar") echo " selected='selected'"; 
  echo '>Bar</option>
    </select>
    <label for="foo_'.$i.'">Foo '.$i.'</label>
    <input id="foo_'.$i.'" type="text" value="';
  if(isset($row['foo_'.$i]) && $row['foo_'.$i] != "") echo $row['foo_'.$i];
    echo '" name="foo_'.$i.'">
    <label for="bar_'.$i.'">Bar '.$i.'</label>
    <input id="bar_'.$i.'" type="text" value="';
  if(isset($row['bar_'.$i]) && $row['bar_'.$i] != "") echo $row['bar_'.$i];
    echo '" name="bar_'.$i.'">';
}