Arrays are a great way of storing variables that natural collect together, such as colours, days of the week, members of a team, or items in a shopping basket.
Multidimensional arrays allow you to store array within arrays to store very complex data in one convenient location.
Use the extract() function to pull all items out of an array and into the global scope, as it is faster and also easier to work with.
Cycle through your arrays using foreach() or similar means, as holes in your array can cause more simple loops to access empty values.
The var_dump() function is a great way to see what is inside your variables, whether they are arrays or not - make liberal use of it when debugging to save headaches!
Next chapter: Exercises >>
Previous chapter: Saving arrays
Jump to: Arrays First steps Associative arrays The two ways of iterating through arrays The array operator Returning arrays from functions Array-specific functions Chopping and changing arrays Stripping out duplicate values Filtering your array through a function Converting an array to individual variables Checking whether an element exists Using an array as a double-ended queue Swapping keys and values Sorting arrays Grabbing keys and values Randomising your array Creating an array of numbers Multidimensional arrays The array cursor Holes in arrays Arrays in strings Saving arrays Summary Exercises Further reading Next chapter
Home: Table of Contents
Follow us on Identi.ca or Twitter
© Future Publishing Limited, Beauford Court, 30 Monmouth Street, Bath BA1 2BW. All rights reserved. England and Wales company registration number 2008885.