好的,在这里尽可能清楚。我正在尝试制作一个pdf文档,其中包含显示产品信息的各个字段。从本质上讲,生成pdf的脚本将确定产品是否已启动更改,如果已启动,则将创建pdf。
我现在要做的是用这些变化来突出这个领域。为了检查是否有变化,我使用了以下变量(其中大约有三十个)
$cone
$ctwo..... etc
PDF文件中产品输出的数组示例为:
$leftHeadArray[0]['leftText'] = 'ID';
$leftHeadArray[0]['rightText'] = $ID;
$leftHeadArray[1]['leftText'] = 'start';
$leftHeadArray[1]['rightText'] = date("d/m/Y", $Start);
$leftHeadArray[2]['leftText'] = 'End';
$leftHeadArray[2]['rightText'] = date("d/m/Y", $End);
格式和单元格在下面的位置初始化:
$maxheader = max(array_keys($leftHeadArray), array_keys($midHeadArray), array_keys($rightHeadArray));
for ($i = 0; $i <= max($maxheader); $i++)
{
if (isset($leftHeadArray[$i]))
{
$pdf->SetFont('helvetica', 'B', 6);
$pdf->SetFillColor(128, 0, 0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1);
$pdf->SetFont('helvetica', 'N', 6);
if ($ctwentytwo == 0 && $leftHeadArray[1]['rightText'] || $ctwentytwo == 0 && $leftHeadArray[4]['rightText'] ){
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(0, 0, 0);
}else{
$pdf->SetFillColor(0, 0, 0);
$pdf->SetTextColor(255, 255, 255);
}
$pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1);
$pdf->Cell(20, 5, '', 0, 0, 'L', 0);
}
我已经尝试过的东西:
围绕单个单元阵列包装if-else语句
(例如$leftHeadArray[0]['leftText']='ID';$leftHeadArray[0]['rightText']=$ID;)
并试图在中超越设置的填充颜色
将if-else语句放入if-iset部分
我正在努力解决的问题:
- 将$cone连接到$leftheadarray
- 启动更改时仅更改一个单元格
我希望这是简洁的!
//------------------------------已解决
变量总是假设为0,因此如果$cone==1,则需要进行解密,并与左头数组相关,如下所示:希望这有帮助!
if (isset($leftHeadArray[$i]))
{
$pdf->SetFont('helvetica', 'B', 6);
$pdf->SetFillColor(128, 0, 0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1);
$pdf->SetFont('helvetica', 'N', 6);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(128, 0, 0);
if (($ctwentytwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Start Date")
|| ($cone == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion ID")
|| ($ctwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Type"))#|| $ctwentytwo == 0 && $leftHeadArray[1]['rightText']
{
$pdf->SetFillColor(0, 0, 0);
$pdf->SetTextColor(255, 255, 255);
}
$pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1);
$pdf->Cell(20, 5, '', 0, 0, 'L', 0);
}
if (isset($leftHeadArray[$i]))
{
$pdf->SetFont('helvetica', 'B', 6);
$pdf->SetFillColor(128, 0, 0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1);
$pdf->SetFont('helvetica', 'N', 6);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(128, 0, 0);
if (($ctwentytwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Start Date")
|| ($cone == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion ID")
|| ($ctwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Type"))#|| $ctwentytwo == 0 && $leftHeadArray[1]['rightText']
{
$pdf->SetFillColor(0, 0, 0);
$pdf->SetTextColor(255, 255, 255);
}
$pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1);
$pdf->Cell(20, 5, '', 0, 0, 'L', 0);
}