PHP Array Element Access
The method to access a PHP array element depends on whether it is a regular array or an associative one.
Let's assume we have a regular array. In this case, access is performed by the element's index in the array (indexing starts from zero):
<?php
$arr = ['a', 'b', 'c'];
echo $arr[0]; // will output 'a'
echo $arr[1]; // will output 'b'
echo $arr[2]; // will output 'c'
?>
Let's assume we have an associative array. In this case, access is performed by the element's key:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
echo $arr['a']; // will output 1
echo $arr['b']; // will output 2
echo $arr['c']; // will output 3
?>
See Also
-
lesson
arrays in PHP