How can you assign consecutive numbers as keys to an array in PHP?

To assign consecutive numbers as keys to an array in PHP, you can use a loop to iterate over the elements you want to add to the array and simply assign them without specifying a key. PHP will automatically assign consecutive numerical keys starting from 0. This is useful when you want to create an indexed array where the keys are sequential numbers.

// Create an array with consecutive numerical keys
$array = [];
for ($i = 0; $i < 5; $i++) {
    $array[] = "Element " . $i;
}

print_r($array);