# Arrays are A brief introduction to the topic

Anyone who has studied programming at university knows that professors tend to give only basic, basic material to their students. The topic of arrays is also covered, but in later courses. Why? Because arrays are the basis that allows the programmer to work with large amounts of information.

## Introduction

Today's topic we will start by introducing a definition for this term. Arrays are elements of the programming environment that represent a set of data in the form of a table or string. Imagine a series of random numbers: 1, 6, 2, 4, 8. This will be an array. Each digit written in a line has its own serial number, and this is what allows you to correlate (enter) them with an array in programming.

## Record

Let's consider how arrays are written in practice. Write, designate arrays - this means specifying for the created program their type (what values will be stored in the array) and the number of cells. Sometimes programmers create dimensionless arrays without specifying the exact number of elements, but then when accessing them, one must be very careful so that the program does not loop and start accessing empty cells.

### D: array[1..k] of real; - this is how an array is written in Pascal. If you know when creating a program that you will have a maximum of 5 elements, then you can use the notation D: array[1..5] of real;

As you might have guessed D is the letter for the name of the array; real is the type (format) of the data that can be contained in the array; array is the number of array elements.

## Appeal

In order to work with an array element, it must be accessed from the program. Arrays are numbers or words just like any other. To work with an element of an array, you must enter: D. This will allow you to select the first element of the array and perform operations on it. For example:

### print (D); - this command will display the value contained in the 1st cell of the array on the user's screen

It is worth noting that if you are going to perform mathematical operations on arrays, then you should pay attention to the type. You can only do this if you have an array of numbers. To make it clearer:

### If you have an array D: array[1..k] of text; - and in the cell D=1, then you will not be able to use this element in mathematical operations, because for the program "1" - it will just be the word "one", not a number. So watch your variables and their types

If you are planning mathematical operations, or the array just needs to store numbers, it's better to worry about its type in advance and assign it to "real" or "integer".

## Table

Let's now talk about the space around us. We live in a three-dimensional world, and most objects can be described by 3 parameters: length, width, height. Likewise, arrays have dimensions. Two-dimensional arrays are tables with data in which each element is assigned not one ordinal number, but two - a row number and a column number. When referring to a two-dimensional array, you must specify both numbers - D[1;1].

Accordingly, such an array will be able to store a larger amount of data. Unfortunately, in the old programming languages, in most cases, only digits can act as the array element number. Therefore, storing data from large tables becomes very problematic due to the fact that each column of the table will have to create a separate array.

For example, let's say we have a table that contains student data. They have: year of birth, last name, class.

 1989 Ivanov Ivan 9 1988 Petrov Peter 10 ….

Under normal circumstances, we would have to create multiple arrays, depending on our needs. We can create one two-dimensional array of numeric type to store the year of birth and class, and a second array to store text information (F. I.). But it's inconvenient. First, the last name and first name may need to be processed separately. Secondly, you can easily get confused when filling the array with the year and class. Therefore, it will be easier to create 4 separate arraysfor each column. Agree, very cumbersome?

## PHP

PHP arrays solve the problem mentioned above. The fact is that in this programming language you can set not only the data type in the array, but also the counter (index) type. In addition, a single array can contain data of various types. Creating a one-dimensional array (if you need to take one column):

### \$array=array(1989, 1988, …);

This is an example of creating a simple array. The index is created automatically and counted from zero. That is, the zero element of the array is 1989, the first element is 1988, and so on. But what if we need to put the entire table into a multidimensional array? What are multidimensional PHP arrays? These are constructs in which each element is also an array. How to parse the example given to us?