In this tutorial you will learn about the PHP Arrays and its application with practical example.
PHP array is a series of elements of the similar type placed in contiguous memory locations that can be accessed individually by adding an index to a unique identifier. An array is made up of a key and a value pair, and the key points to the value.
There are three types of arrays: Indexed array ,Associative array and Multidimensional array.
Indexed Array in PHP
In an indexed array, the keys on index are numeric and starts with 0.
1 |
$students= array("Chrestene","Julie","Saibee"); |
Associative Array in PHP
in associative array, the keys are not necessarily numeric, they are similar to Index arrays in functionality but they are different in terms of their indexing. In associative array indexing is string based.
1 |
$student_marks = array("Chrestene"=>40, "Julie"=>70, "Saibee"=>90); |
Multidimensional Array in PHP
Multidimensional arrays can be described as “arrays of arrays”.Multidimensional arrays are not limited to two indices . They can contain as many indices as needed. The amount of memory needed for an array rapidly increases for each dimension.
1 2 3 4 |
$arr1 = array (7,8,9); $arr2 = array (6,5,4); $arr3 = array (1,2,3); $arr4 = array ($arr1, $arr2, $arr3); |