Authored on: June 21, 2011 by Jeffery Dilegge
![]()
Taking into account that you already know basic PHP coding and the usage of variables, this article will introduce you to the basic use of PHP arrays, as well as explain what they are used for. PHP arrays are similar to normal variables, except they can hold multiple variables. Imagine that you want a variable named "food" to contain a user's top three favorite foods. No matter how you handle this, an array is needed. Eitehr you can store the data in an array initially, or you will have to explode the data into an array when you need to utilize the data. I suggest cuting to the chase and just using a PHP array from the start. You just have to choose what kind of array to use, some types of PHP arrays are better for basic data and others for larger data sets that might even contain mutliple arrays. I will get into the types of arrays in the following tutorials of this PHP array series.
The data structure of a PHP array is organized by KEYs. A KEY can either be a number or a string. A string using numeric keys is called a "Numeric Array" while an array using a strings for keys instead of being numeric, is called an "Associative Array". When using multidimensional arrays with 3 or more dimensions, it is bext practice to use an associative approach so you can organize it better and remember that row is what. A multidimensional array is an array that is layered with multiple arrays.
With arrays, counting starts at zero instead of one. So, the first key or value in any array will be "0" and the second will be "1" and so-on.
PHP.Net has documentation on arrays and array functions here. (opens in a new window)
However, on to my easy to follow php array series:
Next in series: Introduction to php numeric arrays.
Other tutorials in this series: First in series: Introduction to php arrays. Second in series: Introduction to php numeric arrays. Third in series: Introduction to php associative arrays. Fourth in series: Introduction to php multidimensional arrays.
|