The $_REQUEST Variable-php

PHP is a lot more than a way to work with text. You’ve been working with strings
non-stop, but there are a lot more types of information you’ll need to work with
in your PHP scripts. As you might expect, there are all kinds of ways to work with
numbers, and you’ll work with numbers quite a bit before long.
But there’s another really important type of information you need to understand;
in fact, you’ve already been working with this type, as much as you’ve worked with
text. This mystery type is an array: a sort of container that actually holds other
values within it.

Working with $_REQUESTas an Array This special
variable PHP gave you with all the information from a web form, called
$_REQUEST, is also an array. And when you’ve written code like
$_REQUEST['first_name'],
you’ve just been grabbing a particular piece of information out of that array.


foreach($_REQUEST as $value)
{
echo "<p>" . $value . "</p>";
}


Everything between the { }runs once for each time through the loop. So that means
that for every item in $_REQUEST, this line is going to run one time:

echo "<p>" . $value . "</p>";

This line shouldn’t be any big deal to you at all: it just prints out $valuewith some
HTML formatting. But since each time through this loop, $valuehas a different value
from $_REQUEST, it’s a quick way to print out every value in $_REQUEST.


<div id="content">
<p>Here's a record of everything in the $_REQUEST array:</p>
<?php
foreach($_REQUEST as $key => $value) {
echo "<p>For " . $key . ", the value is '" . $value . "'.</p>";
}
?>
</div>


This time, you’re telling foreachto get both the key, as $key, and the value, as $value.
That special =>sign tells PHP you want the $keyand then the $valueattached to
the key. In other words, you’re grabbing a label and the folder that label is attached
to, which is just what you want.