What potential pitfalls should be avoided when creating a Pascal's Triangle in PHP using arrays?

One potential pitfall to avoid when creating a Pascal's Triangle in PHP using arrays is not properly handling edge cases, such as when the number of rows is zero or negative. To solve this, you should check for these cases and return an empty array or handle the error gracefully.

function generatePascalsTriangle($numRows) {
    if ($numRows <= 0) {
        return [];
    }
    
    $triangle = [];
    
    for ($i = 0; $i < $numRows; $i++) {
        $row = [];
        for ($j = 0; $j <= $i; $j++) {
            if ($j === 0 || $j === $i) {
                $row[] = 1;
            } else {
                $row[] = $triangle[$i - 1][$j - 1] + $triangle[$i - 1][$j];
            }
        }
        $triangle[] = $row;
    }
    
    return $triangle;
}

$numRows = 5;
$pascalsTriangle = generatePascalsTriangle($numRows);

foreach ($pascalsTriangle as $row) {
    echo implode(" ", $row) . "\n";
}