0

我正在尝试创建一个 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");
}

谢谢肯尼

4

1 回答 1

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
于 2013-06-26T18:55:22.810 回答