PHP Arrays are a collection of variables, which stores multiple values of same or different datatype at a time.
(or)
Array is a collection of types.The array can hold any type.It can contain strings,integers,floating points and even other arrays.Each of these values inside an array can be accessed with a related key value pair.An array can be created in two ways.array() or array[].Array() function can be used to create an array in PHP.
Array Types
Indexed arrays - These arrays has a numeric index
Associative arrays - These arrays has named keys
Multidimensional arrays - These arrays has one or more arrays.
Every array element in the indexed array stores a numeric index. It can be created in two ways.
1) The assignment of index is done automatically.
[php]
<?php
// Define an indexed array
$names = array("John", "Mike", "Brake");
?>
[/php]
2) The assignement of index is done manually.
[php]
<?php
$colors[0] = "John";
$colors[1] = "Mike";
$colors[2] = "Brake";
?>
[/php]
The keys assigned to the values can be arbitrary and user defined strings in the associative array.
Example
[php]
<!DOCTYPE html>
<html>
<body>
<?php
$age = array("John"=>"24", "Mike"=>"16", "Brake"=>"26", "Hussey"=>"26");
echo "John Age : ".$age['John']."<br/>";
echo "Mike Age : ".$age['Mike']."<br/>";
echo "Brake Age : ".$age['Brake']."<br/>";
echo "Hussey Age : ".$age['Hussey']."<br/>";
?>
</body>
</html>
[/php]
Output:
Multidimensional Arrays
Description
The an array in which every element has the eligibility to become an array and every element in the sub-array follows the same or further contain array within itself and so on.