What potential performance issues can arise when creating the Pascal's Triangle recursively in PHP?

Potential performance issues that can arise when creating Pascal's Triangle recursively in PHP include excessive function calls and redundant calculations. To solve this, we can use memoization to store already calculated values and avoid recalculating them.

function pascalsTriangle($row, $col, &$memo = []) {
    if ($col === 0 || $col === $row) {
        return 1;
    }
    
    if (isset($memo[$row][$col])) {
        return $memo[$row][$col];
    }
    
    $result = pascalsTriangle($row - 1, $col - 1, $memo) + pascalsTriangle($row - 1, $col, $memo);
    $memo[$row][$col] = $result;
    
    return $result;
}

// Example usage
$row = 5;
for ($i = 0; $i <= $row; $i++) {
    for ($j = 0; $j <= $i; $j++) {
        echo pascalsTriangle($i, $j) . " ";
    }
    echo "\n";
}