0

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 Answer 1

1
$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.

Sign up to request clarification or add additional context in comments.

6 Comments

@user3099398. Thanks user3099398 It's working Perfect. I have small Doubt if i have more than 10 arrays it will print or not
If all arrays have same number of elements, Then you have to update headings and add 10 arrays like I did for $array2. Then it will print.
Thanks it's working Perfect. But I have 10 arrays with some values and all value are printing. But it is hidding some cell due to width. can we increase the width of the pdf like, A1, A3 to all values. Can you please guide me. Thanks
Thanks for you help. would please help me i have long heading like mini-Markdown formatting break into like mini-markdown and next line formatting.
How to bold for numbers,animals. and remaining things are normal
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.