How can you access specific elements in an array in PHP?

To access specific elements in an array in PHP, you can use square brackets [] with the index of the element you want to access. The index starts at 0 for the first element in the array. You can also use a loop to iterate through the array and access each element individually.

// Accessing specific elements in an array
$fruits = array("apple", "banana", "orange", "grape");
echo $fruits[0]; // Output: apple
echo $fruits[2]; // Output: orange

// Using a loop to access all elements in the array
foreach($fruits as $fruit) {
    echo $fruit . " ";
}
// Output: apple banana orange grape