Practical PHP Programming:Arrays
From IpbWiki
So far we've looked at the basic variables types such as strings and integers, as well as a variety of functions you can use to manipulate these data types. Beyond the basic data types are arrays and objects, which take a little bit more work in order for you to take advantage of them properly. More importantly, arrays take a solid understanding of functions before you try to use them, which is why they are separated here! As mentioned, objects are covered exclusively in their own chapter - this chapter is dedicated to the topic of arrays.
In order to model our surroundings in a programming environment accurately, it is important to recognise that some types of data naturally group together – colours, for example, naturally clump together into one group. Rather than having hundreds of separate variables – one for each colour – the reality is that it makes more sense to have one variable that holds a list, or array of colours.
Topics covered in this chapter are:
- Reading arrays
- Manipulating arrays
- Multidimensional arrays (arrays of arrays)
- Saving arrays
Chapter contents
- 4.1. Practical_PHP_Programming:Basic array functions
- 4.2. Practical_PHP_Programming:Associative arrays
- 4.3. Practical_PHP_Programming:Iterating over arrays
- 4.4. Practical_PHP_Programming:The array operator
- 4.5. Practical_PHP_Programming:Returning arrays from functions
- 4.6. Practical_PHP_Programming:Array-specific functions
- 4.6.1. Practical_PHP_Programming:Chopping and changing arrays
- 4.6.2. Practical_PHP_Programming:Stripping out duplicate values in arrays
- 4.6.3. Practical_PHP_Programming:Filtering your array through a function
- 4.6.4. Practical_PHP_Programming:Converting an array to individual variables
- 4.6.5. Practical_PHP_Programming:Checking whether an element exists in an array
- 4.6.6. Practical_PHP_Programming:Using an array as a double-ended queue
- 4.6.7. Practical_PHP_Programming:Swapping keys and values in an array
- 4.6.8. Practical_PHP_Programming:Sorting arrays
- 4.6.9. Practical_PHP_Programming:Reading only the keys or values from an array
- 4.6.10. Practical_PHP_Programming:Randomising the order of your array
- 4.6.11. Practical_PHP_Programming:Creating an array sequence
- 4.7. Practical_PHP_Programming:Multidimensional arrays
- 4.8. Practical_PHP_Programming:Walking an array with the array cursor
- 4.9. Practical_PHP_Programming:Holes in arrays
- 4.10. Practical_PHP_Programming:Using arrays in strings
- 4.11. Practical_PHP_Programming:Saving arrays
