dongzhang6677 2016-10-27 07:53
浏览 70
已采纳

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

Hello everybody i am new fpdf. I have multiple array values and create a table.

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

I want to create a table using this values

Numbers Animals
1       Apple
2       Ball
3       Cat

I have tried this way but all values are printing one by one

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();

Can anyone suggestion me how this problem. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dsklfsdlkf1232 2016-10-27 08:08
    关注
    $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();
    

    As FPDF examples you can uses Cell() for display values. And For the Line breaks use Ln(). I assume both $array1 and array2 have similar number of elements. First two Cells use to display headings, then inside the loop display both values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c