The switch statement is wondrous and magic. It's a piece of the language that allows you to select between different options for a value, and run different pieces of code depending on which value is set.
Arrays
An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible. .
Syntax
An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments. array( key => value, key2 => value2, key3 => value3, ...
)
The keys were the numbers we specified in the array and the values were the names of the employees. Each key of an array represents a value that we can manipulate and reference. The general form for setting the key of an array equal to a value is: * $array[key] = value; * | | Programming PHPBy Kevin Tatroe, Rasmus Lerdorf
March 2002
1-56592-610-2, Order Number: 6102
524 pages, $39.95 US $61.95 CA |
Chapter 5
Arrays
As we discussed in Chapter 2, PHP supports both scalar and compound data types. In this chapter, we'll discuss one of the compound types: arrays. An array is a collection of data values, organized as an ordered collection of key-value pairs.
This chapter talks about creating an array, adding and removing elements from an array, and looping over the contents of an array. There are many built-in functions that work with arrays in PHP, because arrays are very common and useful. For example, if you want to send email to more than one email address, you'll store the email addresses in an array and then loop through the array, sending the message to the current email address. Also, if you have a form that