Professional Documents
Culture Documents
26
Note You can learn the various ways of creating arrays in the second half of this chapter.
PHP has several built-in arrays that are automatically populated with useful information. They are
called superglobal
arrays, and all begin with a dollar sign followed by an underscore. Two that you will see frequently are
$_POST and
$_GET. They contain information passed from forms through the Hypertext Transfer Protocol (HTTP)
post and get
methods, respectively. The superglobals are all associative arrays, and the keys of $_POST and $_GET
are automatically
derived from the names of form elements or variables in a query string at the end of a URL.
Lets say you have a text input field called "address" in a form; PHP automatically creates an array
element called
$_POST['address'] when the form is submitted by the post method or $_GET['address'] if you use the
get method.
As Figure 3-4 shows, $_POST['address'] contains whatever value a visitor enters in the text field,
enabling you to
display it onscreen, insert it in a database, send it to your email inbox, or do whatever you want with it.