Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 30th, 2003, 09:38 AM
Authorized User
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default arrays and sessions

I am trying to store an array in a session, and then print the contents of the array out on another page. however I cant get it to work, rather than printing the content of the array it jusy prints "Array".

The code I am using is



$firstquarter=array('January', 'February', 'March');

$_SESSION["firstquarter"] = "$firstquarter";

Then on another page to write the contents of the array


Or if I try this
foreach ($_SESSION["firstquarter"] as $value)
echo "$value<br>";

I get this error
"Warning: Invalid argument supplied for foreach() in C:\Xitami\webpages\results.php on line 97"
Old July 1st, 2003, 04:05 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo


ok here how you should do it bro...

$firstquarter=array('January', 'February', 'March');
$_SESSION["firstquarter"] = $firstquarter;

for ($i=0;$i<count($_SESSION["firstquarter"]);$i++) {
    echo $_SESSION["firstquarter"][$i]; }


hope that helped, peace

the genuine genius
Old April 27th, 2007, 12:16 PM
Registered User
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for providing the solution for why I could not get $_SESSION['myarr[$i]] to work for me. Maybe now I can get the multidimeansonal array working too.

Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions p2ptolu Classic ASP Components 3 March 17th, 2005 06:31 AM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM
arrays and sessions dazednconfused Beginning PHP 9 July 3rd, 2003 01:24 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.