Re: session_name("CCLTrolley")

From: Date: Mon, 03 Oct 2005 03:26:52 +0000
Subject: Re: session_name("CCLTrolley")
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-223544@lists.php.net to get a copy of this message
Robert Cummings wrote:
Is there a reason you're using a comma delimited string? I would recommend using an array instead: <?php session_name( 'CCLTrolley' ); session_start(); // Initialize the trolley. if( !isset( $_SESSION['TrolleyContents'] ) ) { $_SESSION['TrolleyContents'] = array(); } // Add new entry. if( isset( $_POST['RNum'] ) ) { $_SESSION['TrolleyContents'][$_POST['RNum']] = $_POST['RNum']; } echo implode( ',', $_SESSION['TrolleyContents'] ); print_r($_SESSION); ?> Cheers, Rob.
Hi, Still absorbing this array stuff :). I'm getting this error. And when RNum = 1 or = 16 or = 116, it only registers '1', or whatever the first digit is. Warning: Bad arguments to implode() in /var/.../printtrolley.php on line 14 Array ( [TrolleyContents] => 1 3 4 4 5 6 ) I was expecting to see soemthing like: TrolleyContents[16] TrolleyContents[32] TrolleyContents[45] TrolleyContents[48] TrolleyContents[55] TrolleyContents[116] if I have done my homework, since last night ;), correctly? The manual example says: <?php $array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); echo $comma_separated; // lastname,email,phone ?> What is my correct seperator? And why does only one digit get registered? Thanks, John

« previous php.general (#223544) next »