I have a sessions on a page that stores an array
<?php session_start();
if (!isset($_SESSION['pages'])) {
$_SESSION['pages'] = array();
array_push($_SESSION['pages'],$description);
}
print_r($_SESSION['pages']);
?>
Is there a way to limit the array to only 3 descriptions before it rewrites over the first array. For example
array[0] => page1
array[1] => page2
array[2] => page3
no when I visit the 4 page I want it to rewrite over 1 and just keep the 3 records so then it would look like
array[0] => page4
array[1] => page2
array[2] => page3
I don’t know if this is possible or not!
It’s just an array, so it’s very simple.
However, instead I would add an element at the start and remove one at the end if there are more than 3 elements:
That way your order is always the same (last, previous, 2 ago).