如何使用 php 中的数组值创建 pdf

How to create pdf using array values in php

大家好我是新来的fpdf。我有多个数组值并创建一个 table.

$array1=[1,2,3];
$array2=['apple', "ball", "cat"];

我想使用这个值

创建一个table
Numbers Animals
1       Apple
2       Ball
3       Cat

我试过这种方式,但所有值都在一个一个打印

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);

for ($i=0; $i < count($array1); $i++) { 
    [$pdf->MultiCell(30,12,$array1[$i],1), $pdf->MultiCell(30,12,$array2[$i],1)];
    }
$pdf->Output();

谁能告诉我这个问题是怎么回事。 提前致谢。

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

$array1= array(1,2,3);
$array2= array('apple', "ball", "cat");

$pdf->Cell(40,10,'Numbers');
$pdf->Cell(40,10,'Animals');
$pdf->Ln(10);
foreach($array1 as $key=>$row){
    $pdf->Cell(40,10,$row);
    $pdf->Cell(40,10,$array2[$key]);
    $pdf->Ln(10);
}
$pdf->Output();

作为 FPDF 示例,您可以使用 Cell() 显示值。对于换行符,请使用 Ln()。 我假设 $array1array2 都具有相似数量的元素。前两个 Cells 用于显示标题,然后在循环内显示两个值。