title: How to get the specific id from foreach using codeigniter
body: <p>Just want to ask on how to get the ID in a specific foreach</p>
  
  <p>My Controller</p>
  
  <pre><code>public function validate_subtopic(){
  
      $data = array('success' =&gt; false, 'messages' =&gt; array());
      $this-&gt;form_validation-&gt;set_rules("subtopicname", "SubTopicName", "trim|required");
      $this-&gt;form_validation-&gt;set_rules("subtopicdescription", "SubTopicDescription", "trim|required");
      $this-&gt;form_validation-&gt;set_error_delimiters('&lt;p class="text-danger"&gt;', '&lt;/p&gt;');
      if($this-&gt;form_validation-&gt;run()){
          $data['success'] = true;
  
          $subtopic_data = array(
              'subtopicname'          =&gt; $this-&gt;input-&gt;post('subtopicname'),
              'subtopicdescript'  =&gt; $this-&gt;input-&gt;post('subtopicdescription'),
              'subjectID'         =&gt; $this-&gt;input-&gt;post('subjectID'),
              'topicID'           =&gt; $this-&gt;input-&gt;post('topicID'),
              );
  
          $this-&gt;addtopic_model-&gt;insert_subtopic($subtopic_data);
      }
      else{
          foreach ($_POST as $key =&gt; $value) {
              $data['messages'][$key] = form_error($key);
          }
      }
  
      echo json_encode($data);
  }
  </code></pre>
  
  <p>My Model</p>
  
  <pre><code>public function insert_subtopic($subtopic_data){
      $this-&gt;db-&gt;insert('subtopics', $subtopic_data);
  }
  </code></pre>
  
  <p>My view from bootstrap modal</p>
  
  <pre><code>&lt;div class="modal inmodal fade" id="addSubTopic" tabindex="-1" role="dialog"  aria-hidden="true"&gt;
  
      &lt;?php 
      $att = array(
          'method' =&gt; 'POST',
          'id' =&gt; "form-user_sub");
      echo form_open("topicAdd_Controller/validate_subtopic", $att);
      ?&gt;
      &lt;div class="modal-dialog modal-sm"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                 &lt;button type="button" class="close" data-dismiss="modal"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;Close&lt;/span&gt;&lt;/button&gt;
                  &lt;h5 class="modal-title"&gt;Please Input SubTopic&lt;/h5&gt;
              &lt;/div&gt;
              &lt;div id="the-message"&gt;&lt;/div&gt;
              &lt;div class="modal-body"&gt;
  
                  &lt;form role="form"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label&gt;Sub Topic Name&lt;/label&gt;
                          &lt;input class="form-control" name="subtopicname" id="subtopicname" type="text"&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label&gt;Sub Topic Description&lt;/label&gt;
                          &lt;textarea name="subtopicdescription" id="subtopicdescription" class="form-control"&gt;
                          &lt;/textarea&gt;
                      &lt;/div&gt;
                      &lt;?php foreach($sample as $row){
                      ?&gt;
                          &lt;?php $index = current($sample); ?&gt;
                          &lt;input type="text" value="&lt;?php echo $row['topicID']; ?&gt; name="topicID"&gt;
                      &lt;?php } ?&gt;
  
                  &lt;/form&gt;
  
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="button" class="btn btn-white" data-dismiss="modal"&gt;Close&lt;/button&gt;
                  &lt;button type="submit" class="btn btn-primary"&gt;Save&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php form_close();?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>This is the output of $sample:</strong><br> 
  <a href="https://i.stack.imgur.com/uKdRY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uKdRY.jpg" alt="This is the output of $sample"></a><br>
  The problem is I can't get the ID from the specific <code>foreach loop</code> I choose. how can I solve this?
  Please help</p>