PHP foreach with jquery dynamic cloned fields
<p>I have a script where jquery clones a fieldset box with an building, a floor, and a wing (input fields) The user can create as many of these fieldsets as they need.  What I am trying to figure out is this.</p>

<p>I need to main the areas together otherwise I could just loop throug the aray like this.</p>

<pre><code>   foreach ($_POST[$key] as $itemvalue)       { 
         $message .= "\n".$key. " : ".$itemvalue; 
      }
</code></pre>

<p>My first thought was to do this, but of course this was dumb of me </p>

<pre><code>foreach ($_POST['building'] as $value) {
    $count++;
    $message .="\n Area" . $count;
    $message .= "\n Building: ". $value;
    foreach ($_POST['floor'] as $value2){
    $message .= "\n Floor: ". $value2;
        }
    foreach ($_POST['wing'] as $value3){
    $message .= "\n Wing: ". $value3;
        }
    }
</code></pre>

<p>as it just ends up putting each of the floors and wings under every building instead of keep them separate.  </p>

<p>my next thought was to put them into one long for each separated by and &amp;&amp; symbol, but apparently foreach doesn't work this way.</p>

<p>Does anyone have any suggestions on how I can do this?</p>

<p>@stewie I made the modifications you suggested, but I am pretty sure this won't work.</p>

<pre><code>foreach ($_POST['floor'] as $value)
    { $floor = $value; }
foreach ($_POST['wing'] as $value2) { $wing = $value2; }
foreach ($_POST['building'] as $value3)
    { $building = $value3; $building .= $floor; $building .= $wing; }
</code></pre>

<p>This is my entire code, the output I am trying to get is this</p>

<p>Area #1
Building : Building 1
Floor : 2
Wing : East</p>

<p>Area #2
Building : Building 2
Floor : 5
Wing : North</p>

<pre><code>&lt;?php 
if(isset($_POST['submit'])) {

$mailto = "me@myemail.com"; 
$subject = "form"; 
$message = "Values submitted from web site form:"; 
$header = "From: Jeremiah &lt;Jeremiah@myemail.com&gt;"; 

foreach ($_POST['floor'] as $value)
</code></pre>

<p>{</p>

<pre><code>$floor = "\nFloor : " . $value;
}

 foreach ($_POST['wing'] as $value2)
 {
$wing = "\nWing : ".$value2;
 }

 foreach ($_POST['building'] as $value3)
 {
$building = "\n\nBuilding " . $value3;
$building .= $floor ;
$building .= $wing;
$message .= $building;
}




 mail($mailto, $subject, $message, $header); 
 }
</code></pre>

<p>?></p>
