我正在尝试创建一个PHP循环来获取一个起始int变量,并根据每个托盘的wigets数量递增,以获得该托盘的结束变量。然后启动下一个托盘,其中1 +是前一个托盘的结束编号。直到达到总数量。我尝试了几个不同的循环但没有得到我的结果。这是最新的。它会给我托盘的数量,但它保持每个托盘的相同起始编号。
for( $x = 0; $x <= $num_of_skids; $x++)
{
$skid_num++;
$mfg_end_num = $mfg_begin + $per_skid - 1;
$mfg_begin_num = $mfg_end_num + 1;
fputs( $fp, "SKID # " . str_pad($skid_num, 2, " ", STR_PAD_RIGHT) . " " . $cst_prefix . $cst_begin . "-" . $cst_prefix . $cst_end . str_pad( " ", 5, " ") . $mfg_prefix . $mfg_begin_num . "-" . $mfg_prefix . $mfg_end_num . "\r\n");
}
由于 肯尼
答案 0 :(得分:0)
你可以做 -
$mfg_begin_num = $mfg_begin + ($x*$per_skid); // get the 0 based start
$mfg_end_num = $mfg_begin_num + ($per_skid - 1); // subtract 1 due to 0 based loop
使其成为
for( $x = 0; $x <= $num_of_skids; $x++)
{
$skid_num++;
$mfg_begin_num = $mfg_begin + ($x*$per_skid);
$mfg_end_num = $mfg_begin_num + ($per_skid - 1);
fputs( $fp, "SKID # " . str_pad($skid_num, 2, " ", STR_PAD_RIGHT) . " " . $cst_prefix . $cst_begin . "-" . $cst_prefix . $cst_end . str_pad( " ", 5, " ") . $mfg_prefix . $mfg_begin_num . "-" . $mfg_prefix . $mfg_end_num . "\r\n");
}
在这个phpFiddle示例中查看此内容 - http://phpfiddle.org/main/code/5wg-mx2
这输出了这个 -
SKID # 1 XXXXXX-XXXXXX X100-X104
SKID # 2 XXXXXX-XXXXXX X105-X109
SKID # 3 XXXXXX-XXXXXX X110-X114