Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:40:54+00:00 2026-06-11T14:40:54+00:00

I have a sessions on a page that stores an array <?php session_start(); if

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:40:56+00:00Added an answer on June 11, 2026 at 2:40 pm

    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:

    session_start();
    if (!isset($_SESSION['pages']))
    {
      $_SESSION['pages'] = array();
    }
    
    // add an element at the start
    array_unshift($_SESSION['pages'], $description);
    
    // remove an element at the end
    if (count($_SESSION['pages']) > 3)
    {
      array_pop($_SESSION['pages']);
    }
    
    print_r($_SESSION['pages']);
    

    That way your order is always the same (last, previous, 2 ago).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))
I have two pages. On one page I am adding an array to $_SESSION
I have a account page configured like the following; if(!isset($_SESSION[myusername])){ then show some login
So i have a 2 dimensional array that is used over several pages (session)
I have an issue with .scrollTop() I have a page that stores the current
I have a session that stores in an array and I was wondering how
We have various related session variables for a complex page that has various things
My session don't seem to be saved. I have a log in page that
I recently discovered that when you have a page set to session readonly and
For testing I have 1 isolated page - no masters, controls, …. My sessions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.