In computer programming, an array is a collection of elements of the same data type that are stored in a contiguous block of memory and can be accessed using a single variable name. Each element in an array is identified by its index or position within the array, which starts at 0 for the first element.
Arrays are used to store and manipulate large amounts of data in a more organized and efficient way. For example, if you wanted to store a list of names, you could create an array of strings and store each name as an element of the array.
Here’s an example of how to create an array of integers in PHP:
$numbers = array(1, 2, 3, 4, 5);
In this example, we create an array of five integers and assign it to the variable
$numbers. To access an element in the array, you simply use the array variable name followed by the index number in square brackets. For example, to access the first element in the
$numbersarray, you would use the following code:
echo $numbers; // Output: 1