accessing values from an array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
i having trouble accessing the values from superglobal arrays.  there
are two situations but i'm pretty sure it's the same problem.

here's the deal:

on page1.php i have several check boxes.  before listing them i have
the code
$info = array();

and then each checkbox has

<input type="checkbox" name="info[]" value="Red">Red<br>
<input type="checkbox" name="info[]" value="Blue">Blue<br>  ...and so

the form posts to the same page, then checks the info and cleans it up
if needed. then it sets it to a session variable like so:

if (isset($_POST['submitted'])){

$errors = array();

$_SESSION['info'] = escape_data($_POST['info']);} else {
$errors = 'bad';}

then it directs you to the next page, page2.php.

on page2.php,  i can't figure out how to access the array.  i want to
print each element of the array on a seperate line.  w/o all the other
it would look something like:

echo "$info[1]<br>";
echo "$info[2]<br>";

i'd like to do this with a foreach loop but i can't even access one
variable.  not sure where to go from here.

NOTE: when i was doing it earlier and passing the information from page
to page with the post method and then finally sending myself an email
with all the array infromation imploded into a string, it worked fine.

thanks for your time and knowledge.

Re: accessing values from an array

Quoted text here. Click to load it

Shouldn't it be:

echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";

Or, if you want a foreach loop:

foreach($_SESSION['info'] as $val)
   echo $val . " was checked<br/>";

Re: accessing values from an array

thanks, but i've tried that:
Quoted text here. Click to load it

it seems that though $_SESSION['info'] is a set it only contains the
word "Array".  any ideas on that?

thanks again.

Re: accessing values from an array

mtjarrett wrote:
Quoted text here. Click to load it

That's what you get if you just echo $_SESSION because it is an array.



Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline