|  | 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] |