title: Option selected in codeigniter
body: <p>I'm trying to get the option item selected in a form select element using Codeigniter</p>
  
  <p>model</p>
  
  <pre><code>function get_sections_provider($provider)
  {
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('providers');
      $this-&gt;db-&gt;where('providers.id', $provider);
      $this-&gt;db-&gt;join('sections', 'sections.id = providers.section_id');
      $query = $this-&gt;db-&gt;get();
      return $query-&gt;result();
  }
  
  function get_all_sections_element()
  {
      $query = $this-&gt;db-&gt;get('sections');
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>public function edit($id)
  {
      $data['element'] = $this-&gt;admin_model_providers-&gt;get_element_provider($id);
      $data['element']-&gt;sections = $this-&gt;admin_model_providers-&gt;get_sections_provider($id);
      $data['element']-&gt;sections_all = $this-&gt;admin_model_providers-&gt;get_all_sections_element();
      $data['title'] = '';
      $this-&gt;load-&gt;view('admin/admin_provider_edit', $data);
  }
  </code></pre>
  
  <p>view</p>
  
  <pre><code>&lt;?
  foreach($element-&gt;sections as $key =&gt; $row){
      $selected[$key] = $row-&gt;id;
  }?&gt;
  &lt;select name="sections" class="chosen-select" id="" data-placeholder="" multiple&gt;                           
      &lt;?
      foreach($element-&gt;sections_all as $key =&gt; $value){?&gt;
          &lt;option value="&lt;?=$value-&gt;id?&gt;" &lt;?=(in_array($value-&gt;id, $selected) ) ? "selected = 'selected'" : "" ;?&gt; &gt;&lt;?=$value-&gt;title;?&gt;&lt;/option&gt;
      &lt;?}
      ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>The result is the last id
  Sorry, I can not describe in detail the problem because my English is bad</p>