- Indexed arrays - Arrays with numeric index or numeric keys.
Understanding Numeric Index Number - Every value in the array is assigned with an index number. Below image shows how an index number is assigned to a set of values. The first value is assigned with a index value of 0 as the index number always starts with Zero.
Example -
<?php
$numbers = array("one","two","three");
for($i=0; $i<sizeof($numbers); $i++) {
echo $numbers[$i]."<br>";
}
?>
Output:
one
two
three
- Associative arrays - Arrays with string index values or keys. Here we can manually define the value as keys instead of 0's & 1's which we saw in Indexed arrays.The figure below includes the age of few candidates in an array, going by the indexed array will not be the best choice, instead we can use their names as the key. Accordingly we can associate the key to their ages.
Understanding Numeric Index Number - Every value in the array is assigned with an index number. Below image shows how an index number is assigned to a set of values. The first value is assigned with a index value of 0 as the index number always starts with Zero.
Example -
<?php
$numbers = array("one","two","three");
for($i=0; $i<sizeof($numbers); $i++) {
echo $numbers[$i]."<br>";
}
?>
Output:
one
two
three
- Associative arrays - Arrays with string index values or keys. Here we can manually define the value as keys instead of 0's & 1's which we saw in Indexed arrays.The figure below includes the age of few candidates in an array, going by the indexed array will not be the best choice, instead we can use their names as the key. Accordingly we can associate the key to their ages.