title: How to store values of the index in an array?
body: <p>I have an array that looks like this</p>
  
  <pre><code>Array ( [0] =&gt; test1 [1] =&gt; test4 [2] =&gt; test2 )
  </code></pre>
  
  <p>I got this value from my database using Codeigniter built-in function</p>
  
  <p>And whenever I try to insert this value back in my database, it's inserting the <strong>index</strong> instead of the <strong>value</strong> itself</p>
  
  <p>The error I'm getting is
  <a href="https://i.stack.imgur.com/peQg4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/peQg4.png" alt="enter image description here"></a></p>
  
  <p>As you can see, instead of storing test1, test4, test2 in the fields under username, it is storing the index which are 0, 1, 2.</p>
  
  <p>How to fix this please?</p>
  
  <p>References:
  @MichaelK</p>
  
  <p><a href="https://i.stack.imgur.com/TCMAA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TCMAA.png" alt="enter image description here"></a></p>
  
  <p>TABLE:</p>
  
  <p>Project Table
  <a href="https://i.stack.imgur.com/7Kk7b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Kk7b.png" alt="enter image description here"></a></p>
  
  <p>User Table
  <a href="https://i.stack.imgur.com/ELowN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ELowN.png" alt="enter image description here"></a></p>
  
  <p>Project-User Table
  <a href="https://i.stack.imgur.com/OdWCu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OdWCu.png" alt="enter image description here"></a></p>
  
  <p><strong>VIEW</strong></p>
  
  <pre><code>&lt;div class="panel-body"&gt;
      &lt;?php echo form_open('admin/add_recommended'); ?&gt;
      &lt;div class="form-group col-lg-12"&gt;
      &lt;label&gt;Recommended Employees:&lt;/label&gt;
      &lt;?php echo form_error('skillsRequired'); ?&gt;
      &lt;?php
          foreach ($users as $row) {
              $user[] = $row-&gt;username;  
          }
          print_r($user);
          echo form_multiselect('user[]', $user, $user, array('class' =&gt; 'chosen-select', 'multiple style' =&gt; 'width:100%;'));
       ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="panel-footer"&gt;
      &lt;?php echo form_submit(array('id' =&gt; 'success-btn', 'value' =&gt; 'Submit', 'class' =&gt; 'btn')); ?&gt;
      &lt;?php echo form_close(); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>public function add_recommended() {
          $this-&gt;form_validation-&gt;set_rules('skillsRequired', 'Skills Required', 'min_length[1]|max_length[55]');
  
          $lid = $this-&gt;admin_model-&gt;getID();
  
          foreach ($lid as $id) {
              $last_id = $id['projectID'];
              $data['users'] = $this-&gt;admin_model-&gt;getUsers($last_id);
          }
          $this-&gt;load-&gt;view('admin/projects/rec-employee', $data);
  
          if ($this-&gt;form_validation-&gt;run() === FALSE) {
              //$this-&gt;load-&gt;view('admin/projects/rec-employee');
          } else {
              $users = $this-&gt;input-&gt;post('user');
              print_r($users);
  
              foreach ($users as $user) {
                  $data = array(
                      'projectID' =&gt; $last_id,
                      'username' =&gt; $user
                  );
  
                  $id = $this-&gt;admin_model-&gt;insert('projectemp', $data);
              }
  
              if ($id) {
                  $this-&gt;session-&gt;set_flashdata('msg', '&lt;div class="alert alert-success" role="alert"&gt;Success! New Project has been added.&lt;/div&gt;');
                  redirect('admin/add_recommended');
              }
          }
      }
  </code></pre>
  
  <p><strong>RENDERED VIEW</strong>
  <a href="https://i.stack.imgur.com/Yt0oq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yt0oq.png" alt="enter image description here"></a></p>