An array is a particular variable in computer programming languages that can carry several values under a single name. The values can then be accessed by referring to an index number or a text key.
Because WordPress is developed in the PHP programming language, you may encounter them while working on WordPress themes or plugins, or just by reading at the core WordPress code. The array() function in PHP is used to make them. In PHP, there are three sorts of objects that can be created:
- Numeric keys are used to access values that are indexed.
- Text or string keys are used to access values in an associative database.
- More than one array can be found in a multidimensional array.
Arrays are commonly used to loop through a set of data and perform operations on each value. If you have three pieces of fruit, for example, you could save each as a different variable like follows:
$fruits_1 = "apple";
$fruits_2 = "orange";
$fruits_3 = "banana";
This can rapidly become a disaster. Putting them all in an array like this would be a better solution:
$fruits = array("apple", "orange", "banana");
You may now conduct actions on the data by using built-in array functions. For example, count() will return the number of elements in your array. ‘Banana’ would be equal to $fruits[2] (arrays start at zero).
Example in WordPress:
The $args variable is an array that holds several parameters. Later on, these are supplied to the wp list categories function.
<?php
$args = array(
'taxonomy' => 'category',
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => 'Categories'
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>