title: How to delete row from session array and again order array list?
body: <p>I have a web site which enables user to add or delete their own favorite books. I added "add" and "delete" button every row in page. I can add favorite books in session array and there is no problem about it. But I can not delete a row from "user's favorite book list."   </p>
  
  <p>I used jquery, ajax. I could unset row but what I want is delete that row from session completely and order again. Despite the fact that I unset the row, element number of session does not change.   </p>
  
  <p>Here is code :  </p>
  
  <pre><code>    //There are rows in $newdata. That is to say, newdata array is not empty now.
      // I just add newdata array here to show that there is an array called newdata.
  
      var $newdata = array();
  
      function delete_row($rowid) {
  
      if (isset($rowid)) {
  
      $this-&gt;newdata = $this-&gt;session-&gt;userdata('contents');
      unset($this-&gt;newdata[$rowid]['id']);
      unset($this-&gt;newdata[$rowid]['name']);
      unset($this-&gt;newdata[$rowid]['author']);
      unset($this-&gt;newdata[$rowid]['year']);
  
      $this-&gt;session-&gt;set_userdata(array('contents' =&gt; $this-&gt;newdata));
  
      $contents = $this-&gt;session-&gt;userdata('contents');
  
      $i = 0;
  
          foreach ($contents as $key)         
          {
              if ($key['id'] != "") {
                  $i++;
  
              $this-&gt;newdata[$i]['id'] = $key['id'];
              $this-&gt;newdata[$i]['name'] = $key['name'];
              $this-&gt;newdata[$i]['author'] =$key['author'];
              $this-&gt;newdata[$i]['year'] =$key['year'];
  
              } else {
  
              }
          }
  
      $this-&gt;session-&gt;set_userdata(array('contents' =&gt; $this-&gt;newdata));
  
      } else {
  
          echo "There is no row to be deleted";
      }
  }
  </code></pre>
  
  <p>Here is view code(html) : </p>
  
  <pre><code>&lt;div&gt;
  
          &lt;?php 
  
          if (count($contents)==0) {
          echo 'There is no favorite book';
          } else {
  
          echo '&lt;table class="table table-striped"&gt;';
  
          $i = 0;
          echo count($contents);
          foreach ($contents as $items) {
  
          echo '&lt;tr&gt;';
          echo '&lt;td&gt;'.$items['id'].'&lt;/td&gt;';
          echo '&lt;td&gt;'.$items['name'].'&lt;/td&gt;';
          echo '&lt;td&gt;'.$items['author'].'&lt;/td&gt;';
          echo '&lt;td&gt;'.$items['year'].'&lt;/td&gt;';
          echo '&lt;td&gt;&lt;button id='.$i .' class="delete_row"&gt;&lt;b&gt;DELETE&lt;/b&gt;&lt;/button&gt;&lt;/td&gt;';
          echo '&lt;/tr&gt;';
          $i++;
  
      }
      echo '&lt;/table&gt;';
  
      }
          ?&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is jquery code : </p>
  
  <pre><code>$('.delete_row').click(function(event) {
  event.preventDefault();
  var id = $(this).attr("id"); 
  window.location.href = '/favorite/delete_row/'+id;
  
   });
  </code></pre>