title: Populate dynamic checkbox with dynamic values codeigniter
body: <p>I have a form with add and edit function. Inside the form, they have checkboxes. The checkboxes itself is generated from mysql table.</p>
  
  <p>When I want to do add function, the checkbox are populated correctly. However, I have issue when I entering edit function of the form.</p>
  
  <p>I need the checkbox values are checked based when I do submit.</p>
  
  <p>Here is my code:</p>
  
  <p><b>Controller:</b></p>
  
  <pre><code>public function edit($id)
  {
      $data['query'] = $this-&gt;Campaign_model-&gt;edit($id);
      $data['branch_list'] = $this-&gt;Campaign_model-&gt;get_branch_list();
      $data['branch_checked'] = $this-&gt;Campaign_model-&gt;get_checked_branches($id);
  
      $this-&gt;load-&gt;view('campaign_form', $data);
  }
  </code></pre>
  
  <p>The <code>$data['branch_list']</code> contains the primary checkboxes. The <code>$data['branch_checked']</code> contains which checkboxes are checked within current data (query).</p>
  
  <p><b>View:</b></p>
  
  <pre><code>$branch_id = "";
  
  foreach($branch_list as $branch_list_checkbox)
  {
      if($branch_list_checkbox-&gt;id == $branch_checked-&gt;branch_id)
      {
          $branch_id .= '&lt;label&gt;&lt;input name="branch_id[]" type="checkbox" value="'.$branch_list_checkbox-&gt;id.'" checked /&gt;'.$branch_list_checkbox-&gt;name.'&lt;/label&gt;&amp;nbsp;';
      }
      else
      {
          $branch_id .= '&lt;label&gt;&lt;input name="branch_id[]" type="checkbox" value="'.$branch_list_checkbox-&gt;id.'" /&gt;'.$branch_list_checkbox-&gt;name.'&lt;/label&gt;&amp;nbsp;';
      }           
  }
  </code></pre>
  
  <p>Everything in <code>$branch_list</code> are populated properly. But how do I assign the <code>$branch_checked</code> properly to their respective checkboxes?</p>
  
  <p>Need help, thanks.</p>