我需要将迭代次数转换为 1 到 7 之间的范围。
$y = keepInRange(1, 7, $i)
结果输入->输出预计如下
- 1 -> 1
- ...
- 7 -> 7
- 8 -> 1
- 9 -> 2
- ...
- 14 -> 7
- 15 -> 1
我已经尝试过以下但没有成功:
min(7, max(1, $numberToStr[$i])) (all output 1)
$y = $i % 7 (all outputs 0, Edit: this was a mistake by me, its the solution when +1 is added.)
最佳答案
试试这个
<?php
$num = 15;
$res= $num%7;
if($res == 0)
{
echo "7";
}
else
{
echo $res;
}
希望对你有帮助
关于php - 将迭代次数转换为有限范围(如星期几),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38183563/