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…

AJAX: What it is and how to use it in Scriptcase

Hello, in this post we will conceptually understand the AJAX event and how use  inside the Scriptca...

What advantages for a company in adopting a low-code tool?

Let's understand how low-code tools have become a facilitator in the web development process as they...

How to implement A2F using Swivel in a Scriptcase application

I want to start talking about Swivel, Swivel is a provider of authentication solutions who have been...

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.