title: Wrap array elements in divs based on same value
body: <p>After fetching results from mysql, is it possible to group the array elements with the same values from the field <code>id_group</code> and wrap them in div elements. Can anyone give me soem suggestions?</p>
  
  <p>Here's the output I want:</p>
  
  <pre><code> &lt;div class="id_group_1"&gt; 
     &lt;div&gt;comment from group 1&lt;/div&gt;
     &lt;div&gt;comment from group 1&lt;/div&gt;
     &lt;div&gt;comment from group 1&lt;/div&gt;
   &lt;/div&gt;
  
   &lt;div class="id_group_2"&gt;
     &lt;div&gt;comment from group 2&lt;/div&gt;
     &lt;div&gt;comment from group 2&lt;/div&gt;
     &lt;div&gt;comment from group 2&lt;/div&gt;
     &lt;div&gt;comment from group 2&lt;/div&gt;
     &lt;div&gt;comment from group 2&lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>  $id_group = $_POST["group"];
    $reply = $_POST["reply"];
    $sql = "SELECT a.comments,b.name,a.id_group from `reviews` a 
            INNER JOIN `users` b 
            ON a.app_id = b.id  
            WHERE a.post_name = ? 
            AND a.id_group IN ($in) 
            ORDER BY a.id_group";
  
    $users = $dbh-&gt;prepare($sql);
    $users-&gt;bindValue(1,$reply);
    $i = 3;
    foreach ($id_group as $id) {
      $users-&gt;bindValue($i++, $id);
    }
    $users-&gt;execute(array_merge(array($reply), $id_group));
  
    //*****Here*****//
    foreach($users as $row)
    {
      echo "&lt;div&gt;".$row["comments"]."&lt;br&gt;Written by ".$row["name"]."&lt;/div&gt;";  
    }
  </code></pre>