Information Technology Reference
In-Depth Information
15
It's very easy to forget that the first item is numbered 0, the second is numbered 1, and so on. This
problem is not unique to computing; in the United Kingdom, you walk into a building on the ground
floor, and have to go up to the first floor; in the United States, the ground floor is the first floor.
Computing just brings this long-standing confusion to new areas of endeavor (see Figure 15.2).
Figure 15.2
Arrays let you choose a variable's value
from a list. When writing your script, ref-
erence the number, not the name. Note
that the series starts with zero.
0
pink
1
yellow
2
teal
bgcolor
(Background color)
3
green
Select
One
4
violet
5
tan
Indexed arrays are just one of three main array types in PHP. Associative arrays use named keys,
one of the reasons they are sometimes called dictionaries. The third type is called multidimensional ,
and it holds more than one set of key/value pairs, thus they are “arrays of arrays.”
As you will see later in this chapter, the $_GET and $_POST arrays are among the most important
PHP items in WordPress. These arrays are called superglobals in PHP, meaning they are available to
you in all PHP scripts and need not be declared. What are they?
We have to backtrack a little bit and remind you that PHP is a language that only runs inside a web
server. Looked at another way, PHP has access to any data that passes through the server. The
server receives requests that use an assortment of methods, but mostly just two: GET and POST .
The superglobal arrays allow any script to obtain data from each of those requests.
The GET method is used most often for search results, and its chief
advantage is that it creates a unique URL (that can be bookmarked
or otherwise referenced) based on the query string. The POST
method passes data invisibly, and does not create a unique URL.
WordPress uses GET to pull in the different parts of a theme into
your site.
note
The POST method (and resulting
$_POST array in PHP) is not the
same as a blog post.
Search WWH ::




Custom Search