How can you efficiently loop through an array in PHP without knowing the length of the first key?

When looping through an array in PHP without knowing the length of the first key, you can use a foreach loop to iterate over the array elements. This allows you to access each element without needing to know the length of the array beforehand. By using a foreach loop, you can efficiently loop through the array regardless of its size.

$array = [1, 2, 3, 4, 5];

foreach ($array as $element) {
    echo $element . "\n";
}