What potential errors or pitfalls can occur when trying to store positions of ones in a two-dimensional array in PHP?

When trying to store positions of ones in a two-dimensional array in PHP, a potential error could occur if the positions are not stored correctly or if the array is not properly initialized. To avoid this, ensure that the array is initialized with the correct dimensions and that the positions of ones are stored accurately within the array.

// Initialize a two-dimensional array with a specific size
$rows = 5;
$cols = 5;
$array = array_fill(0, $rows, array_fill(0, $cols, 0));

// Store positions of ones in the array
$positions = [[0, 1], [2, 3], [4, 4]];
foreach ($positions as $pos) {
    $array[$pos[0]][$pos[1]] = 1;
}

// Display the array to verify positions of ones
foreach ($array as $row) {
    echo implode(" ", $row) . PHP_EOL;
}