By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,130 Members | 2,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,130 IT Pros & Developers. It's quick & easy.

accessing values from an array

P: n/a
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
on

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();

if(!empty($_POST['info'])){
$_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.
-michael

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>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>";


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/>";

Nov 22 '05 #2

P: n/a
thanks, but i've tried that:
echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";


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

thanks again.

Nov 22 '05 #3

P: n/a
mtjarrett wrote:
thanks, but i've tried that:
echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";

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

thanks again.


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

Try

print_r($_SESSION);
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.