【发布时间】:2018-04-20 20:36:57
【问题描述】:
我的尝试在下面;首先以while loop 开始创建数组,然后使用foreach 遍历每个数组,以尝试计算数组中的每个项目。
$begin = $_POST['startpoint'];
$end = $_POST['endpoint'];
$current_start = $begin;
$num1 = 3;
$num2 = 355;
while ($i = $begin; $i <= $end; ++$i) {
$array[] = $i;
foreach ($array as &$counted) {
echo '<span>Star SC ' + $counted + ' mag ' + $num1 + $num2;
}
}
想要的输出是这样的;如果用户插入说10002 和80000:
输出 1.) Star C 69998 mag...
和
输出 2.)
10002
10003
10004
10005
(一直到80000)
html:
<form action="script.php" method="post">
<input type="number" name="startpoint" min="100000" max="999998">
<input type="number" name="endpoint" min="100001" max="999999">
<input type="submit" name="submit" value="Go!" />
</form>
更多细节:我想数数,所以在每个用户输入的数字之间进行数学运算(即69998);并显示之间的每个数字,以上面的用户示例为例;它将是10002、10003、10004 - 一直到80000。
【问题讨论】:
-
你只想做数学?
-
你使用了错误的while循环,你应该使用
for
标签: php foreach while-loop