What are some alternative methods to incrementing a counter variable within a loop when creating arrays in PHP?

When creating arrays within a loop in PHP, you may need to increment a counter variable to keep track of the array index. Instead of manually incrementing the counter variable using the $i++ syntax, you can use alternative methods such as the foreach loop or the array_push function to dynamically add elements to the array without explicitly managing the counter variable.

// Using foreach loop to create an array without needing a counter variable
$array = [];
foreach ($items as $item) {
    $array[] = $item;
}
```

```php
// Using array_push function to add elements to an array without managing a counter variable
$array = [];
for ($i = 0; $i < count($items); $i++) {
    array_push($array, $items[$i]);
}