title: Unable to unset an item from Laravel session array
body: <p>I am trying to use <code>unset/array_splice</code> to remove an index of an item from an array, in the context of Laravel sessions.</p>
  
  <p>What I have is:</p>
  
  <ol>
  <li><p>Check if <code>class</code> session key exists</p></li>
  <li><p>If so, get it, and loop through it</p></li>
  <li><p>If that particular index's element (a string) matches the input string (from an AJAX request), unset it, and <code>put</code> the new unsetted array BACK to the session</p></li>
  </ol>
  
  <p>This operation, <em>in theory</em> (story of my life), should remove an item from the cart. </p>
  
  <pre><code>// Remove the item [if exists]
  if(Session::has('class')) {
      $classes = Session::get('class');
      foreach($classes as $index =&gt; $class) {
          if($data['class'] === $class) {
              array_splice($classes, $index, $index - 1);
              Session::put('class', $classes);
  
              return Response::json(array(
                      'success' =&gt; true,
                      'code' =&gt; 1,
                      'message' =&gt; $data['class'] . ' removed from cart'
                  )
              );
          }
      }
  }
  </code></pre>
  
  <p>The data within the <code>class</code> session looks like this:</p>
  
  <pre><code>[
     "ECEC 471 Introduction to VLSI Design Lab",
     "ECEC 471 Introduction to VLSI Design Lecture",
     "ECEC 413 Introduction to Parallel Computer Architecture Lecture",
     "ECEC 457 Security in Computing Lecture &amp; Recitation"
  ] 
  </code></pre>
  
  <p>I traced the code logically a couple times, but it does not unset the item. I know the string is matched, since my JSON response from the shown query is returned.</p>
  
  <p>EDIT:</p>
  
  <p>Ok, so I made a little breakthrough. </p>
  
  <ol>
  <li><p>I forgot to assign the key to <code>put</code> in the session, so I've changed it to this: <code>Session::put('class', $data)</code></p></li>
  <li><p>Next, due to how the indices things work with <code>array_splice</code>, the unsetting works for all indices greater than 1. If the current index you want to unset is <code>0</code> or <code>1</code>, it fails, since respectively, the "new" index turns to <code>-1</code> and <code>0</code>..</p></li>
  </ol>