To find the first element of an array in PHP, you can use the indexing notation with the index value of zero (0
). Here's an example:
main.php115 chars6 lines
In this example, the $array
variable is an indexed array with three elements. We use the indexing notation to access the first element of the array using the index value of 0
. We store this value in the $first_element
variable and then use echo
to display the value to the user.
Note that if the array is empty or doesn't have an element at index 0
, this code will generate a notice error.
gistlibby LogSnag