In PHP, what are some efficient ways to iterate through an array and display specific elements based on their position?

When iterating through an array in PHP and displaying specific elements based on their position, one efficient way is to use a loop (such as a for loop) to iterate through the array and check the index of each element. Based on the index, you can choose to display or skip certain elements.

// Sample array
$array = ['apple', 'banana', 'cherry', 'date', 'elderberry'];

// Display elements at specific positions
for ($i = 0; $i < count($array); $i++) {
    if ($i % 2 == 0) { // Display elements at even positions
        echo $array[$i] . "<br>";
    }
}