
PHP AND MYSQL WEB DEVELOPMENT
viii
Associative Arrays ................................................................................73
Initializing an Associative Array ....................................................73
Accessing the Array Elements ........................................................73
Using Loops with each() and list() ..................................................74
Multidimensional Arrays ......................................................................75
Sorting Arrays ......................................................................................79
Using sort() ......................................................................................79
Using asort() and ksort() to Sort Associative Arrays ......................79
Sorting in Reverse ..........................................................................80
Sorting Multidimensional Arrays ........................................................80
User Defined Sorts ..........................................................................80
Reverse User Sorts ..........................................................................82
Reordering Arrays ................................................................................83
Using shuffle() ................................................................................83
Using array_reverse() ......................................................................84
Loading Arrays from Files ....................................................................85
Other Array Manipulations ..................................................................88
Navigating Within an Array: each, current(), reset(),
end(), next(), pos(), and prev() ....................................................88
Applying Any Function to Each Element in an Array:
array_walk() ..................................................................................89
Counting Elements in an Array: count(), sizeof(), and
array_count_values() ....................................................................90
Converting Arrays to Scalar Variables: extract() ............................91
Further Reading ....................................................................................92
Next ......................................................................................................92
4 String Manipulation and Regular Expressions 93
Example Application: Smart Form Mail ..............................................94
Formatting Strings ................................................................................96
Trimming Strings: chop(), ltrim(), and trim() ................................96
Formatting Strings for Presentation ................................................97
Formatting Strings for Storage: AddSlashes() and StripSlashes() 100
Joining and Splitting Strings with String Functions ..........................101
Using explode(), implode(), and join() ........................................102
Using strtok() ................................................................................102
Using substr() ................................................................................103
Comparing Strings ..............................................................................104
String Ordering: strcmp(),strcasecmp(), and strnatcmp() ............104
Testing String Length with strlen() ..............................................105
Matching and Replacing Substrings with String Functions ..............105
Finding Strings in Strings: strstr(), strchr(), strrchr(), stristr() ......106
Finding the Position of a Substring: strpos(), strrpos() ................107
Replacing Substrings: str_replace(), substr_replace() ..................108
00 7842 FM 3/6/01 3:38 PM Page viii
Comentarios a estos manuales