title: How to use multiple variables in array
body: <p>I'm working on a recipe inventory list. Users would be able to input multiple ingredients where each ingredient has a <strong><em>name</em></strong> (tomato, onion, milk), <strong><em>amount</em></strong> (5 tomatos, 1 onion), <strong><em>measurement</em></strong> (oz, tbsp, cup) and <strong><em>fractions</em></strong> if required (1/4 cup, 1/2 tbsp, 3/4 tsp). I want to keep each as a separate variable so that I can later use that to create a grocery list.</p>
  
  <p>Would I be able to use the foreach function to make this work? How might I be able to set up four variables into an array for each ingredient that I can use?</p>
  
  <p>Or is there an alternate way of doing this? Multple values for one variable maybe? </p>
  
  <pre><code>&lt;?php
  $recipe = $_POST["recipe"];
  $ingredient_amount_01 = $_POST["ingredient_amount_01"];
  $fractions_01 = $_POST["fractions_01"];
  $measurement_01 = $_POST["measurement_01"];
  $ingredient_01 = $_POST["ingredient_01"];
  if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Recipes&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form method="post" action="&lt;?php echo $PHP_SELF;?&gt;"&gt;
  
  Recipe Name:&lt;input type="text" size="12" maxlength="12" name="recipe"&gt;&lt;br /&gt;
  Ingredients&lt;br /&gt;
  
  1:&lt;select name="ingredient_amount_01"&gt;
  &lt;option value=""&gt;Amount...&lt;/option&gt;
  &lt;option value="1"&gt;1&lt;/option&gt;
  &lt;option value="2"&gt;2&lt;/option&gt;
  &lt;option value="3"&gt;3&lt;/option&gt;&lt;/select&gt;
  
  &lt;select name="fractions_01"&gt;
  &lt;option value=""&gt;---&lt;/option&gt;
  &lt;option value="one_quarter"&gt;¼&lt;/option&gt;
  &lt;option value="one_half"&gt;½&lt;/option&gt;
  &lt;option value="three_quarters"&gt;¾&lt;/option&gt;&lt;/select&gt;
  
  &lt;select name="measurement_01"&gt;
  &lt;option value=""&gt;Measurement...&lt;/option&gt;
  &lt;option value="cup"&gt;Cup&lt;/option&gt;
  &lt;option value="oz"&gt;Oz&lt;/option&gt;
  &lt;option value="scoop"&gt;Scoop&lt;/option&gt;
  &lt;option value="slice"&gt;Slice&lt;/option&gt;
  &lt;option value="tablespoon"&gt;Tbsp&lt;/option&gt;
  &lt;option value="teaspoon"&gt;Tsp&lt;/option&gt;&lt;/select&gt;
  
  &lt;input type="text" size="12" maxlength="100" name="ingredient_01" placeholder="Ingredient"&gt;&lt;br /&gt;
  
  &lt;input type="submit" value="submit" name="submit"&gt;
  &lt;/form&gt;
  
  &lt;?
  } else {
  echo "Hello. Here is the recipe for &lt;b&gt;" .$recipe. "&lt;/b&gt; that you've submitted.&lt;br /&gt;";
  
  echo "Ingredients:&lt;br /&gt;";
  foreach ($ingredient as $g) {
  echo $g &lt;-- This would show something like, 2 1/2 cup milk --&gt;. "&lt;br /&gt;";
  }
  echo "Recipe:".$recipe."&lt;br /&gt;";
  echo "Item Amount:".$ingredient_amount_01."&lt;br /&gt;";
  echo "Fractions:".$fractions."&lt;br /&gt;";
  echo "Measurement:".$measurement."&lt;br /&gt;";
  echo "Ingredient:".$ingredient."&lt;br /&gt;";
  }
  ?&gt;
  </code></pre>