How can arrays be effectively filled within a for loop in PHP?

When filling an array within a for loop in PHP, you can use the loop index as the key for the array. This allows you to easily add elements to the array as the loop iterates. Simply create an empty array before the loop, then use the loop index to assign values to the array inside the loop.

// Create an empty array
$array = [];

// Loop to fill the array
for($i = 0; $i < 5; $i++) {
    $array[$i] = "Element " . $i;
}

// Print the filled array
print_r($array);