php - 通过参数函数返回替代数字基数
问题描述
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
解决方案
推荐阅读
- reactjs - Tailwind CSS - mx-auto 不居中 div 元素?
- c++ - C++17 静态模板惰性求值
- c# - Rotate in the y axis Quaternion
- python - 比较文件中的原始字节而不是解释的 str 字节
- ubuntu - Nginx 无法启动,因为我犯了一个错误,不知道如何反转它
- file - 尝试将 .jmx 文件上传到 Jmeter 时出现意外错误
- javascript - inRange 没有定义?(Javascript)
- excel - Power Query/Power BI Match Pattern Fix Suite # in Address
- java - 如何在java中读取,然后逐块写入一个大文件
- c# - Visual Studio Code C#(MacBook Pro Apple M1)调试不起作用