473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

accessing values from an array

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
3 1544
>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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting everything to PHP5. I have session variables in all of my web application. Until PHP5 I was using session variables like: if ($_SESSION == 'Bar') { $value = 5;...
6
by: ASPfool | last post by:
Hello everyone, Please help me before I throw my computer out of the window: I'm working on a web application in classic ASP (vbscript), which is making calls to some webservices. The calls...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
1
by: Jason Bell | last post by:
Every example of properties I've seen have used simple types such as integers and strings. Here's the scenario I'm trying to work out (3D graphics programming): I have a class called...
3
by: Bob Altman | last post by:
Hi all, In unmanaged C++, I need to allocate an "array" of int values, put values into the array, then call a function and pass it the address and length of the array. The length of the array...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
4
by: vanderr | last post by:
Hi everyone. I've recently been asigned a program where we are required to create a 2D array dynamically and then do stuff with it. We are not allowed to "cheat" and use the 1D method. in the...
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.