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

时间:2018-03-11 07:54:05

标签: php fpdf

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

enter image description here

Image Above是我正在显示的项目。最后一项是最后一次迭代。最后一项的第一个值是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 个答案:

答案 0 :(得分:0)

我想你不应该写入最后一个值,直到你加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
相关问题