title: How to remove an element at the end and add an element at start in array PHP
body: <p>Ok so I am banging my head against the wall, but am not able to figure this out, am making recent items list in PHP where I want too add an element to start of an array and remove 1 at the end after I've 5 elements in the array but this is not working</p>
  
  <pre><code>if(!isset($_SESSION['recent_items'])) {
      $_SESSION['recent_items'] = array();
  }
  
  if(isset($_SESSION['recent_items'])) {
      if(count($_SESSION['recent_items']) &lt;= 4) {
          array_push($_SESSION['recent_items'], $script_id);
      } else {
          array_shift($_SESSION['recent_items']);
          array_unshift($_SESSION['recent_items'], $script_id);
      }
  }
  </code></pre>