Jump to content

Recommended Posts

Thanks! Didn't know about the sessions function before.

However, I would like to echo a value of an array, through its position within the array.

So what I've done is basically:

Webpage A

session_start();
$_SESSION['fruits'] = $fruits;
$fruits = array('apple', 'banana', 'pear');

 

Webpage B

session_start();
echo $_SESSION['fruits'][3];

 

It doesn't give me the value of pear but a string offset error, so how should I go about doing this?

You have to store the value in the variable before saving it in the session.

 

use this

session_start();
$fruits = array('apple', 'banana', 'pear');
$_SESSION['fruits'] = $fruits;

session_start();
echo $_SESSION['fruits'][3];

before you try out the script, clear your session first using.

 

create a new php file and run it

 

<?php
session_destroy();
?>

 

this will ensure it destroys all the previous session used.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.