title: Group permission list with checkbox based on name and action
body: <p>I have set of data permissions on mysql:</p>
  
  <pre><code>|=====================|==================|
  |      name           |        action    |
  |=====================|==================|
  |     setting         |         add      |
  |---------------------|------------------|
  |     setting         |         view     |
  |---------------------|------------------|
  |     setting         |         delete   |
  |---------------------|------------------|
  |     task            |         add      |
  |---------------------|------------------|
  |     task            |         delete   |
  |---------------------|------------------|
  |     report          |         view     |
  |---------------------|------------------|
  </code></pre>
  
  <p>and i would like to display the permission on table like example below:</p>
  
  <pre><code>|=====================|======================|
  |      permission     |  add | view | delete |
  |=====================|======================|
  |     setting         |  []  |  []  |   []   |
  |---------------------|----------------------|
  |     task            |  []  |      |   []   |
  |---------------------|----------------------|
  |     report          |      |  []  |        |
  |---------------------|----------------------|
  </code></pre>
  
  <p>Group each row by name and only show the checkbox where the action same as the column header, below is my code so far, but it still show the checkbox even the action is not same as the column header.</p>
  
  <pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;add&lt;/th&gt;
      &lt;th&gt;view&lt;/th&gt;
      &lt;th&gt;delete&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt; 
  &lt;tbody&gt;
  &lt;?php
  $permissionTitles = array();
  foreach($permissions as $permission){
      $permissionTitles[] = $permission['name'];
  }
  foreach(array_unique($permissionTitles) as $permissionTitle){
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;".$permissionTitle."&lt;/td&gt;";
    foreach($permissions as $permission){
      if($permission['name'] == $permissionTitle) {
          echo "&lt;td&gt;&lt;input type='checkbox' value=".$permission['value']."&gt; 
          &lt;/td&gt;";
      }
    }
    echo "&lt;/tr&gt;";
  }
  ?&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>$permissions is from database, it is an array :</p>
  
  <pre><code> Array(
    [0] =&gt; Array(
       [name] =&gt; setting
       [action] =&gt; add
    )
    [1] =&gt; Array(
       [name] =&gt; setting
       [action] =&gt; view
    )
   ....
  )
  </code></pre>
  
  <p>Any help is very appreciated.</p>