You are here: Re: [PHP] Sending arrays from page to page « PHP « IT news, forums, messages
Re: [PHP] Sending arrays from page to page

Posted by Dan Lowe on 11/15/05 20:28

On Nov 15, 2005, at 12:07 PM, Ben Miller wrote:

> I am trying to learn how to work with arrays, and have the basic
> concept
> down for working within a single page, but I am having trouble
> sending an
> array from one page to another. For example, I can send a variable
> from
> page to page using either the URL, such as www.domain.com/?foo=bar,
> or using
> a form, but can I send an array from one page to another using a
> form so
> that all the values in the array will be sent? Such as:

The easy way to do this is with sessions; be it strings, numbers,
arrays, whatever.

<?php

session_start();

$_SESSION['myarray']['one'] = 1;
$_SESSION['myarray']['two'] = 2;
$_SESSION['myarray']['three'] = 3;
$_SESSION['myarray']['four'] = 4;
$_SESSION['myarray']['five'] = 5;

// Now you have array $_SESSION['myarray'] with your values in it

?>

And then any page with session_start() should load all the values
stored in $_SESSION on subsequent pages. Much easier than messing
around with forms and submitting from page to page. Since $_SESSION
itself is an array, you can load it up with anything you want -
strings, numbers, other arrays, other nested arrays, etc.

<?php

$_SESSION['blah'] = 'foo';
$_SESSION['count'] = 5;

$_SESSION['myarray']['five']++; // five is now 6

?>

-dan


--
To announce that there must be no criticism of the President, or that
we are to stand by the President, right or wrong, is not only
unpatriotic and servile, but is morally treasonable to the American
public. -Theodore Roosevelt, 1918

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация