How to Install Operating System ??Complete Guide Installing The Operating System

Definition of Array

e-bookcomputer.com – In this basic PHP tutorial section 10 we will discuss the definition of array, what is an array? An array is types of Array that are arguably unique, different from other basic types of data such as integers, strings, and others. definition of array can store one or more data in a single variable, according to their function, the types of array are very useful for storing lots of data in one variable.

Before going forward, there are a number of articles that you might be looking for.

Read too :

How do the Types Of Array work? in the programming language, any data type array is actually the same in terms of its use, ie where each array element has each index can be a string or integer, this index array is used to access each different array value.

Types of Array in PHP

There are several types of arrays that can be used, in the definition of array, all types of arrays, only the way they are used are different, several types of arrays are Numeric Arrays, Associative Arrays, and Multidimensional Arrays. Here is each brief description of each array type:

1. Numeric Array

Numeric arrays are types of arrays where the index elements contained in them are defined by numbers, usually, the first index starts with the number “0” and so on.

2. Associative Array

An associative array is different from an array of numeric types, these types of array define its index using a name or name to be able to access the values of the array elements.

3. Multidimensional Arrays

Multidimensional arrays are methods of storing data array values more than one array, this means arrays in arrays, multidimensional arrays are very useful for storing variable values with lots of data even though it is more difficult to use but this type of array is more efficient in user because it can hold a lot of data.

From each array no more which is the best, all usage depends on needs and usage.

Example Writing Types of Array in PHP

In addition to the above theory, we need to know is the way of writing or the types of array that will be shown through the PHP web programming language, here are each of the examples of writing.

Numeric Array

As stated above, an array of numerics is an array that uses the index with numeric numbers to be able to access its values, there are two ways to write this numeric array.

Automatic Index

This means that the automatic index here is writing an array by not specifying an index or key array, writing an array with this automatic index starting from the index value “0”.

<?php
$data = array ('wine', 'mango', 'melon');
?>

…or

<?php
$data [] = 'wine';
$data [] = 'mango';
$data [] = 'melon';
?>

From the above array values to be able to see each array index can use two basic PHP functions, namely using var_dump () or print_r (), here the author uses print_r () to practice this tutorial, the method is:

<?php
print_r ($data);
?>

From the code above, it will display as shown below:

Definition of Array
Definition of Array

Index Manual

The purpose of the manual index is the opposite of automatic index, which is an index array whose value is determined by itself, for example:

<?php
$data [0] = 'wine';
$data [1] = 'mango';
$data [2] = 'melon';
?>

In an index that can be determined, you can freely want to give an index value as a key to your liking, use the first method to be able to see the array display, which can be by using the var_dump () or print_r () function.

Associative Array

In contrast to numeric arrays, this associative array index is manually determined, can be a string or number and only by using the symbol “=>” as a pointer to the value of the index. example:

<?php
$data = array ('buah1' => 'wine', 'buah2' => 'mango', 'buah3' => 'melon');
?>

Let’s look at the appearance of this associative array using print_r ().

Definition of Array
Definition of Array

Multidimensional Array

Unlike the previous examples of arrays, multidimensional arrays can hold more than one array in one variable, meaning arrays in arrays, for example:

<?php
$data = array (
                array ('wine', 'mango', 'melon'),
                array ('orange', 'apple', 'guava'),
                array ('pineapple', 'banana', 'pear')
              );
?>

The following is a display of the results of a multidimensional array.

Definition of Array
Definition of Array

It can be seen that this multidimensional array is more complex to use, where we can store a lot of data in one variable, but it is more difficult to manage these types of array.

So this tutorial about arrays, to be able to use arrays and arrange them to use loops like for each, while or for. The benefits of this array tutorial will be felt if we have integrated PHP with the database, where to set the values contained in the database, most use arrays.

Before proceeding, there are a number of articles that might be looking for.

Also read :

Sending
User Review
0 (0 votes)

Add a Comment

Your email address will not be published. Required fields are marked *