title: How to group multiple form inputs in php form for sending
body: <p>I have a very simple form for products. Each product has a checkbox and quantity field that repeat creating an array of data like this:</p>
  
  <pre><code>&lt;form action="process.php" method="post"&gt;
  &lt;input type="checkbox" name="product[]" value="product 1" /&gt;
  &lt;input type="text" name="quantity[]" /&gt;
  
  &lt;input type="checkbox" name="product[]" value="product 2" /&gt;
  &lt;input type="text" name="quantity[]" /&gt;
  
  &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Then I handle this form the following way in php:</p>
  
  <pre><code>//php script to retrieve data
  $product    = isset($_POST['product'])  ? implode(', ', $_POST['product'])  : 'Not selected'; 
  $quantity   = isset($_POST['quantity']) ? implode(', ', $_POST['quantity']) : 'Not mentioned'; 
  
  $messageToSend = &lt;&lt;&lt;END
  
  Products:  $product - $quantity
  
  END;
  </code></pre>
  
  <p>And the output result is for example: <strong>Products: product 1, product 2 - 10, 2</strong></p>
  
  <p>But what I am trying to achieve is the following output:
  <strong>Products: product 1 - x 10, product 2 - x 2</strong></p>
  
  <p>Basically what I am trying to figure out is how to split and group data for each product in php script after I retrieved data.</p>
  
  <p>Your help is very much appreciated.</p>