In computer programming languages, an array is a special variable that can hold more than one value under a single name. It is possible to then access the values by referring to an index number or a text key.
WordPress is written in the PHP programming language and hence as a WordPress user you may come across them while working on WordPress themes or plugins or by simply looking at the core WordPress code. In PHP, the array() function is used to create them. There are three types that can be created in PHP:
- Indexed – use a numeric keys to access values
- Associative – use text or string keys to access values
- Multidimensional – contain more than one array
Many arrays are used to loop through a set of data and perform some sort of operation on each value. For example if you have three pieces of fruit you could store each as a separate variable like this:
This can quickly get very messy. A better solution would be to put them all in an array like this:
Now you can do things like use built in array functions to perform operations on the data. For example, count() would tell you how many elements are in your array. $fruits would equal ‘banana’ (arrays start at zero).
Example in WordPress:
The $args variable is an array, storing a number of arguments. These are then passed in to the wp_list_categories function later on.