首页 > 解决方案 > 通过参数函数返回替代数字基数

问题描述

function solution($N)
{
$corect = true;
$str = "";
for ($i = 0; $i < $N; $i++) {
    if ($corect) {
     LINE 9:  $str += '+';
    } else {
        $str += '-';
        $corent = !$corent;
    }

}
return $str;
}

echo solution(10);

我想通过函数参数返回替代数字,如 $N= 3 输出: +-+ 。我试图这样做,但我在控制台中收到了这个错误

  PHP Warning:  A non-numeric value encountered in line 9 

标签: phpalgorithm

解决方案


推荐阅读