Chapter 10. Arrays

You already learned a little about arrays, those pesky little sets of variables, and in this chapter, we are going to review what we already know and learn a lot more about them. Arrays are very useful in PHP programming, and you will find them in probably every advanced program you see. When using a form to submit a value, the variables are stored in an array, which is passed along to the new page. This array is used for calculations and data recall.

PHP documentation explains an array as an ordered map that has a set of keys that each has a value. You create the keys in the array; keys are names that reference the individual items in an array. Sometimes a set of consecutive numbers is used, and other times a set of strings is used. Because all elements of an array have the same name, you need some way to keep them separate. For example, when using the $_GET[] array, the key was whatever was in the brackets. For example, the $_GET['fullname'] key was fullname. Often, the key is a number, so you can have a set of arrays from 0 to 10 looking like $array[0] to $array[10].

Arrays are particularly strong if you use integers with them and want to initialize a large number of values. for loops can do this very easily, using a for loop to set each individual element of an array. Arrays and loops are natural companions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.217.167