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.
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.
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.
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”.
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:
From the code above, it will display as shown below:
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:
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.
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:
The following is a display of the results of a multidimensional 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.