FPDF - 如何用 foreach 中的新单元覆盖第一个单元

FPDF - How to overwrite first cell by a new one inside foreach

您好,我正在使用 FPDF 生成 PDF 文件。我正在使用 FPDFCell 函数显示 foreach 中的每个项目。现在我有一个条件语句来获取最后一个 iteration 或我的 foreach 中的最后一项并在其中添加某个值。之后我需要用新值覆盖(显示)最后一次迭代。

上图是我展示的项目。最后一项是最后一次迭代。最后一项的第一个值是 263.50 并且在我得到它之后因为它是最后一次迭代。我在其上添加 .01 值为 263.51。 我可以显示新值,但旧值仍然存在。

这是我的示例代码

$this->SetXY(29, $y);
$this->SetFont('Arial','',8.5);
$this->Cell(18,4,$value_of_ins = str_replace(',', '', number_format($inscost_conv, 2)),1,0,'R'); // this line is to display the items

    if ($i == $len - 1) { // to get the last iteration

    $value_of_ins = $value_of_ins + 1;

    $this->SetXY(29, $y);
    $this->SetFont('Arial','',8.5);
    $this->Cell(18,4,$value_of_ins,1,0,'R'); // display the last item with new value

  }
    $i++;

我想你不应该写最后一个值,直到你给它加 1。像这样:

$this->SetXY(29, $y);
$this->SetFont('Arial','',8.5);

$value_of_ins = str_replace(',', '', number_format($inscost_conv, 2));
if ($i == $len - 1) {
    $value_of_ins += 1
}

$this->Cell(18,4,$value_of_ins,1,0,'R'); // this line is to display the items