Array Basics PHP Essential Training

Array Basics PHP Essential Training

PHP

Array Basics PHP Essential Training

Array is a variable but it can handle a collection of data which is have a series of variables that will can store unlimited data under a single name. It is like a table structure, in basic array variable it has only one column and multiple rows. In Array basics PHP Essential Training we learn how the array worked in PHP.
In multi dimensional array it has more than one columns and multiple rows. First we learn the basic array and its functionalities. The array declaration is differentiate than the other variables we've seen in our previous examples. The syntax of the array is like follows,
// &arrayName is the Name of the array we want to use, array is a keyword and inside the () give the values you want to store separated by commas.
$arrayName = array(" " => , ' ');

// Example
$array1 = array(4, 8, 12, 16, 20, 24);
echo "Array [1]: " . $array1[1] . "<br />";
Just change the position of the array and check how the it returns the values from the columns. If we change the array reference to 0.
echo "Array [0]: " . $array1[0];
// We get 4 as we expected
Array Basics PHP Essential Training
Like the other programming languages our PHP also has nested array or multiple arrays. Here we go with some example for the arrays inside the arrays and its functionalities.
// Here we have some fun with array inside the array.
$array2 = array(6, "HTML", "PHP", array("Apple", "Google", "Twitter"));
echo $array2[1] . "<br />";
// Lets see what is in the pocket number 3
echo $array2[3] . "<br />";
// Here the [3] is mention the value of fourth row in the first column and [1] is defines the second value in the inside array
echo $array2[3][1] . "<br />";
Array Basics PHP Essential Training
We can dynamically change the values inside the array by assign another value to the column exactly. Here we show you how to changes the fourth position in the $array2.
$array2[3] = "Microsoft";
echo $array2[3] . "<br />";
Array Basics PHP Essential Training

Array Basics PHP Essential Training

Some time we are interested in what kind of date stored in the array. So in Array Basics PHP Essential Training they are using the positions or labels which is an identifier for each value on the array list. It is little bit cozy to remember the positions in the very large array list. Consider the following example how the labels are easily remember the key value pairs.
$array3 = array("first_name" => "Android", "last_name" => "Hotspot");
// Here we access the value by its label name
echo $array3["first_name"];
Array Basics PHP Essential Training
Like the labels we can also use the numbers to point out the location of the exact data in the array list. Follow the next example how to do it.
$array3 = array(1 => "Android", 2 => "Hotspot");
//This shows how to points the value by using both an ordinary number and label name of the position
echo $array3[1] . " " . $array3["last_name"];
Before moving to the next lesson Array Functions PHP Essential Training, there is one more thing to tell you about the array basics php essential training. We can use some functions to show the over all structure of an array and what it have inside in individual positions. Lets see how to do that.
//As we seen in array2, it has the nested array. so we apply the print_r to that array
print_r($array2);
Array Basics PHP Essential Training
These are the basic functions in the array structure. We hope this lesson will help you to understand array basics. To know more about Floating point Numbers go to our previous lesson. Our next lesson will be the array functions in depth and see you there.
Download the source Code of Array Basics PHP Essential Training from here.

Leave a Reply