How can PHP arrays be automatically added to a second dimension of an array in a loop?

To automatically add PHP arrays to a second dimension of an array in a loop, you can create a new array for each iteration of the loop and then push that array into the main array. This way, each iteration will add a new element to the second dimension of the main array.

// Initialize the main array
$mainArray = [];

// Loop to add arrays to the second dimension of the main array
for($i = 0; $i < 5; $i++) {
    $newArray = [1, 2, 3]; // Example array to be added
    $mainArray[] = $newArray;
}

// Output the main array
print_r($mainArray);