To access an element at a specific index in an array in PHP, you can use square brackets notation. Here is an example:
// Define an array
$array = [10, 20, 30, 40, 50];
// Access the element at index 2
$element = $array[2];
// Output the element
echo $element; // Output: 30
In this example, the array has elements [10, 20, 30, 40, 50]
. To access the element at index 2 (which is 30
), we use $array[2]
. The value 30
is assigned to the variable $element
, and we can output it using echo
.