What potential issues can arise when using array_push within a recursive while loop in PHP?

When using array_push within a recursive while loop in PHP, potential issues can arise with the scope of the array variable. Each recursive call creates a new instance of the array variable, which can lead to unexpected behavior or loss of data. To solve this issue, you can pass the array variable as a reference to the recursive function.

function recursiveFunction(&$array, $limit) {
    if ($limit > 0) {
        array_push($array, $limit);
        recursiveFunction($array, $limit - 1);
    }
}

$array = [];
recursiveFunction($array, 5);

print_r($array);