Taking 2 steps to create an array. Can it be done in one?

Hi All,

I have a set of values on an HTML page.

I’ve been taking the values one at a time from the CGI:

[php]$month3=$_REQUEST[‘month3’];
$day3=$_REQUEST[‘day3’];
$year3=$_REQUEST[‘year3’];[/php]

And then creating an array directly:

[php]
$row = array {
“month3” => $month3,
“day3” => $day3,
“year3” => $year3
};[/php]

Seems there should be a way to combine those two steps? I also need the values (i. e. $month3) for use elsewhere in the program. Can’t figure out how to generate key value pairs, or something…

Thanks!

Hi there,

This should be what you are looking for. It’s quite straightforward:

[php]$row = array(“month3” => $_REQUEST[‘month3’],
“day3” => $_REQUEST[‘day3’],
“year3” => $_REQUEST[‘year3’]);[/php]

Hope this helps.

OK, I get that part of it and thanks, but if I later need to reference those values by name, how do I do it?

Hi again,

If you are going to need to reference them later, you would use the array like you regularly would: $row[‘month3’] and such. If you are wanting to reference the $_REQUEST information later on, as long as the script you have this code in is active, you can use $_REQUEST to reference them. If you want to use the values for other scripts, you would need to store them in a $_SESSION variable and use session_start() on all of your pages using the $_SESSION variables.

Hope this helps.

Opz, you’re awesome. Thanks so much!

Sponsor our Newsletter | Privacy Policy | Terms of Service