« a mishmash of basic php | main | includes and functions »
arrays in php
23 Jan 08
- an array is a type of variable used to store a set of values (that much I knew)
- numerically indexed arrays are indexed numerically (!) starting at 0
- an array can be initialized directly or an array can be created by copying from another array using the = operator
- an array can also be created using data stored in a file, or in a database
- loops are convenient ways to access numerically indexed arrays
- an associative array allows the association of any key or index with each value
- the each() function can be used to loop through an associative array
- the list() function can be used to split an array into a number of values – I assume this corresponds to the number of associations
- multidimensional arrays are created by nesting
- one advantage of associative arrays is that data can be accessed by the name of the key, which makes more sense than a simple digit
- thus it is easier to identify and access a single value in a complex array
- however, looping is simpler with numerically indexed arrays, so these will be preferable in some situations
Welling, Luke and Laura Thomson. PHP and MySQL Web Development. 2nd ed. Indianapolis: Sam’s, 2003.
Posted by pzed on January 23, 2008 at 5.44pm
Categories: libraries, music, web stuff
