Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Arrays - new PHP user

Status
Not open for further replies.

ChocolateLover

Programmer
Jan 5, 2006
12
GB
I'm learning PHP and I have created a $_SESSION that holds this array.
Array ( [booking_dates] => [book] => Array ( [0] => 2006-01-20 [1] => 2006-01-27 ) )
How do I access the dates to be able to use them? In other words, how do I refer to the 'book' array and loop through it?

Any help gratefully received, thanks.

In case you need more details, I have an availability page with a form called 'book', within this form there are checkboxes called 'booking_dates[]' and their values are dates. I want to pass the booking_dates array to my booking page, where I will list the dates.

In my availability page I have used
Code:
if (isset($_POST['book'])) {
   $_SESSION['book']=$_POST['book'];
   $URL='booking.php';
   header ("Location: $URL"); 
}

Thanks again.
 
you are storing the dates in a multidimensional array. try
Code:
echo $_SESSION['booking_dates]['book'][0];

to loop through the array
Code:
foreach ($_SESSION['booking_dates]['book'] as $date):
  echo $date ."</br>";
endforeach;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top