In this tutorial, you shall learn how to get the first element in given array in PHP using array[index] notation, with the help of example programs.
PHP – Get first element in array
To get first element in array in PHP, we can use array index notation.
The expression to get the first element in array
index=0 represents the first element in the array.
In this example, we take an array
arr with some elements. We get the first element in the array and print it to output.
<?php $arr = ["apple", "banana", "cherry"]; $first_element = $arr; echo $first_element; ?>
In this PHP Tutorial, we learned how to get the first element in array using array indexing notation.