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

  • SEARCH
  • Home
  • 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 8558607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:51:03+00:00 2026-06-11T15:51:03+00:00

I have a session that stores in an array and I was wondering how

  • 0

I have a session that stores in an array and I was wondering how I would go about if the person visits the same page it doesn’t add it to the array and if an array value is empty don’t echo the results, this is an example

$SESSION['image'][0] => page1

they visited page1 so it is logged. Now if they go back to the page the array looks like this

$SESSION['image'][0] => page1
$SESSION['image'][1] => page1

Also I echoed out the title and thumbnail image of the last 3 pages visited, but if they have cleared their history or first time visiting the site the images are broken because there is no data in the array. This is what I have tried

if(!empty($_SESSION['image'][1]) {
echo ' <div>$_SESSION[/'image/'][1]</div>
}

I use this to keep the array updating the first 4

if (!isset($_SESSION['image']))
{
$_SESSION['image'] = array();
}
array_unshift($_SESSION['image'], $rentals['Image']);
if (count($_SESSION['image']) > 4)
{
array_pop($rentals['Image']);
}

However is there a better way to just keeping the array at 4 values and dumping the values after 4?

Wow this turned out to a long question, my apologies :-/

  • 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-11T15:51:04+00:00Added an answer on June 11, 2026 at 3:51 pm

    I think array_slice function is what you need to keep array size in bounds. Check this out:

    <?php 
    $a = array(1);
    print_r(array_slice($a, -4));
    
    $a = array(1, 2, 3, 4, 5);
    print_r(array_slice($a, -4));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sessions on a page that stores an array <?php session_start(); if
I have a popup that stores a DataTable into a session so that after
I have a certain session variable that is actually an array. I want to
We have various related session variables for a complex page that has various things
I have a session that contains an array. The array contains the following data:
So i have a 2 dimensional array that is used over several pages (session)
I have the following that stores the previous 10 URL's into a session: function
I have the session created and it stores the data, that is working 100%;
I have a site that stores an array in sessions. Items are added to
I try unsuccessful to access from my portlet the session attribute that I have

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.