Arrays, also known as vectors, are widely used in programming to solve logical problems, often related to processing information in queue, stack or list.

arrays

An array consists of different positions that may be accessed via the respective command, which indicates the position by name or number.

By definition, the array is nothing more than a mathematical data structure, a pattern where the values ​​can be stored in rows and columns. This way you can organize the data and use them later.

 

CREATING ARRAYS IN PHP

The creation of an array in PHP can be done in two ways. In the first example we have an array being created using the array () function without the indication of the constructor:

<? Php

Vet $ = array ();

$ Vet [‘Name’] = “Luiza”;

$ Vet [‘Phone’] = “11-33224555”;

$ Vet [‘Balance’] = 90,000;

?>

Note that each position of the array is determined by a name that describes the stored value and the stored value that is assigned to the respective position.

This structure is widely used in functions that return database queries. Each position of the array is indicated with the name of the column.

In the next example we have a different situation:

<?

$ Ar1 = array (‘value1’, ‘value2’, “value3”, “value x ‘);

print_r ($ ar1);?>

 

 

To use the function builder, each position receiveS Na indicator number and the stored value will be then rescued as follows:

ar1 [0] = value1

ar1 [1] = value2

ar1 [2] = value3

ar1 [3] = value x

The first position of the array will always be the zero position. Therefore, when one rescues the information you need to consider this item.

The use of the repetition structure is often used when it is necessary to go through an array in order to manipulate their values. In the following example, let’s go a four-position array, printing on screen the value of each position.

<? Php

$ Ar1 = array (‘value1’, ‘value2’, “value3”, “value x ‘);

for ($ var = 0; $ var <4; ++ $ var)

{

echo ($ ar1 [$ var] “.”);

}

?>

The zero position until the three position, all values ​​will be printed on screen sequentially. It is important to be alert to stop parameter since, when accessing a non-existent position, the system will return an error advising that could not perform the action and the function will no longer run.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.