title: Problems when using nested foreach on checkboxes loaded dynamically
body: <p>I need to use nested foreach for dependent checkboxes.</p>
  
  <pre><code>    &lt;input type="checkbox"  name="all[]" value="&lt;?php echo $row_bus_details['busid'];?&gt;" &gt;
  
       &lt;?php
        $book_side_result = mysqli_query($db,"select * from advt_sides");
                                             while($book_side_row=mysqli_fetch_array($book_side_result))
      {
                                             ?&gt;
     &lt;input type="checkbox" name="bookingside[]" value="&lt;?php echo $book_side_row['advt_side_id']; ?&gt;" id="&lt;?php echo $book_side_row['advt_side']; ?&gt;&lt;?php echo $row_bus_details['busid'];?&gt;" &gt; &lt;?php echo $book_side_row['advt_side']; ?&gt;&lt;br/&gt;
                                            &lt;?php } ?&gt;
  </code></pre>
  
  <p>I need to loop the selected values of second checkbox if the first checkbox is selected.</p>
  
  <p>I wrote the code like</p>
  
  <pre><code>$i = 0;
             $busid = isset($_POST['all']) ? $_POST['all'] : array();
             foreach ((array)$busid as $item) {
  
  
         if(!empty($_POST['bookingside'])) {
              foreach($_POST['bookingside'] as $side) {
                  $sql_book_side=mysqli_query($db,"INSERT INTO `advt_book_side`(bus_id,sides_id) VALUES ('$item','$side')");
                  $i++;
              }
          }
       }
  </code></pre>
  
  <p>The result I need is just like the image below</p>
  
  <p><a href="https://i.stack.imgur.com/Kfkqq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kfkqq.png" alt="required output"></a></p>