title: About to store multiple values of child checkbox related to parent checkbox, data is stored only one time
body: <p>When I store services and activity then services and activity value store multiple times in the database, I also use implode instead of foreach but that time first service and first activity stored, the following image describes the idea about what I exactly want.</p>
  
  <pre><code>&lt;form method='post' id='userform' action='savecheckbox.php'&gt; &lt;tr&gt;
  &lt;td&gt;Trouble Type&lt;/td&gt;
  &lt;br&gt;
  &lt;td&gt;
   &lt;input type='checkbox' name='servicevar[]' value='1'&gt;tds&lt;br&gt;    &lt;br&gt;
  
  &lt;input type='checkbox' name='activityvar[]' value='1'&gt;Return&lt;br&gt;
  &lt;input type='checkbox' name='activityvar[]' value='2'&gt;Filling&lt;br&gt;
  &lt;br&gt;
  
  
   &lt;input type='checkbox' name='servicevar[]' value='2'&gt;Gst&lt;br&gt;    &lt;br&gt;
  &lt;td&gt;
  
  &lt;input type='checkbox' name='activityvar[]' value='1'&gt;Return&lt;br&gt;
  &lt;input type='checkbox' name='activityvar[]' value='2'&gt;Filling&lt;br&gt;
  &lt;br&gt;
  
  &lt;input type='checkbox' name='servicevar[]' value='3'&gt;vat&lt;br&gt;    &lt;br&gt;
  &lt;td&gt;
  
  &lt;input type='checkbox' name='activityvar[]' value='1'&gt;Return&lt;br&gt;
  &lt;input type='checkbox' name='activityvar[]' value='2'&gt;Filling&lt;br&gt;
  &lt;br&gt;
  &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type='submit' name="submit" class='buttons'&gt; 
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;?php 
  if(isset($_POST['submit']))
  {
      $activity = $_POST['activityvar'];
      $service = $_POST['servicevar'];
  
      foreach ($service as $key =&gt; $servicevalue)
      {
          foreach($activity as $key=&gt;$activityvalue)
          {
              $query = "insert into serviceacitivitymap(service_id,activity_id)values('$servicevalue','$activityvalue')";
              $insert_row = $conn-&gt;query($query) or die ($conn-&gt;error.__LINE__);
          }
      }
  }
  </code></pre>
  
  <p>?></p>
  
  <ul>
  <li><strong>Recent output image</strong></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/ZTKuE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZTKuE.png" alt="enter image description here"></a></p>
  
  <ul>
  <li><strong>expected output image</strong></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/MQE6W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MQE6W.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/MQE6W.png" rel="nofollow noreferrer">2</a>: </p>