Arrays are variables used by WordPress developers when they need to be able to store multiple values under a single name. For example, if a WordPress developer wants the ability to store various makes and models of automobiles, but doesn’t want to create a separate variable for each piece of data, he or she could create an array labeled “$cars” or something similar.
So, in this scenario, storing multiple vehicles in the array might appear as:
$cars = array("Ford Mustang", "Chevrolet Blazer", "Toyota Corolla");
This allows the developer to do things such as perform various operations on the data.
In contrast, at one point, developers would have had to utilize separate variables to achieve the same goal. For example, using some basic forms of programming, storing the same information would have appeared as:
$cars1 = "Ford Mustang"; $cars2 = "Chevrolet Blazer"; $cars3 = "Toyota Corolla"
And so on. As you can see, it could quickly become quite tedious to do this, particularly if the programmer was working with large sets of data. Using an array instead saves time and simplifies the overall structure of the code. Further, it allows developers to reduce the potential for errors by reducing the amount of code they must create.← Back to Glossary