title: Converting Array to String Codeigniter 3.0
body: <p>I am trying to insert an element into my 'category' table and use the inserted element's id to insert another element into my 'subcategory' table.</p>
  
  <p>This is my code in my controller</p>
  
  <pre><code>public function insertCategory(){
      $category = $this-&gt;input-&gt;post('category');
      $subcategory = $this-&gt;input-&gt;post('subcategory');
  
      $this-&gt;form_validation-&gt;set_rules('category', 'Category', 'required');
      $this-&gt;form_validation-&gt;set_rules('subcategory', 'Subcategory', 'required');
  
      if($this-&gt;form_validation-&gt;run() == FALSE){
          $this-&gt;load-&gt;view('ADMIN_ADDCategory');
      }
      else{
          $category_id = $this-&gt;admin_model-&gt;insertCategory($category);
          $this-&gt;admin_model-&gt;insertSubcategory($category_id, $subcategory);
      }
  }
  </code></pre>
  
  <p>And this is my code in my model</p>
  
  <pre><code>function insertCategory($category){
      $data = array(
          'category' =&gt; $category,
          'status' =&gt; 1
      );
      $this-&gt;db-&gt;insert('category', $data);
      $this-&gt;db-&gt;select('id');
      $this-&gt;db-&gt;from('category');
      $this-&gt;db-&gt;where('category', $category);
      $this-&gt;db-&gt;limit(1);
      $query = $this-&gt;db-&gt;get();
      return $query-&gt;result();
  }
  
  function insertSubcategory($category_id, $subcategory){
      $data = array(
          'category_id' =&gt; $category_id,
          'subcategory' =&gt; $subcategory,
          'status' =&gt; 1
      );
      $this-&gt;db-&gt;insert('subcategory', $data);
  }
  </code></pre>
  
  <p>However I am getting this error</p>
  
  <p><a href="https://i.stack.imgur.com/cDqJ5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cDqJ5.jpg" alt="enter image description here"></a></p>
  
  <p>I already tried using <code>$category_id = (array) $this-&gt;admin_model-&gt;insertCategory($category);</code> but it still doesn't work</p>
  
  <p>How do I overcome this error? Thank you for the help.</p>