Help me in solving WALK problem using PHP

My issue

My code is throwing a runtime error when I try to use the bcadd function of PHP to add two integers. How can I add two large numbers in PHP? Please help.

My code

<?php

$t = readline();

for($i = 0; $i < $t; $i++) {
    $n = readline();
    $a = explode(' ', readline());
    
    
    $val = $n;
    
    for($j = 0; $j < $n; $j++) {
        if($val < $a[$j]) {
            $val += $a[$j] - $val;
        }
        $val--;
    }
    
    print(bcadd($val, $n) . PHP_EOL);
}

Problem Link: Walk Practice Coding Problem - CodeChef

@mr_try_hard
refer the following code for debugging

<?php

$t = (int)trim(fgets(STDIN));

while ($t--) {
    
    $n = (int)trim(fgets(STDIN));
    
    $w = explode(' ', trim(fgets(STDIN)));
    
    $minV = $n;
    
    for ($i = 0; $i < $n; $i++) {
        if ($minV - $i < $w[$i]) {
            $minV = $w[$i] + $i;
        }
    }
    
    echo $minV, "\n";
    
}