Harinder Harinder - 1 month ago 5
PHP Question

Pass Foreach Value In a PHP Class

How can i pass foreach value in a class , here is my code

$pdf->addPDF('samplepdfs/1.pdf', 'all')
->addPDF('samplepdfs/2.pdf', 'all')
->addPDF('samplepdfs/3.pdf', 'all')
->addPDF('samplepdfs/4.pdf', 'all')
->addPDF('samplepdfs/all.pdf', 'all')
->merge('file', 'samplepdfs/all1.pdf');


I am trying to pass value by catching post from form

foreach($_POST['docs'] as $att ){
$nAtt .= "addPDF('$path.$att', 'all')->" ;
}


$pdf->$nAtt.merge('file', $mergeName);


but this its not working. Pleas help.

Answer

do the adding inside the loop

foreach($_POST['docs'] as $att ){
    $pdf->addPDF($path.$att, 'all');
}


$pdf->merge('file', $mergeName);