Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以使用更少的isset行来循环数组键吗?_Php_Dry_Fpdf_Isset - Fatal编程技术网

Php 我可以使用更少的isset行来循环数组键吗?

Php 我可以使用更少的isset行来循环数组键吗?,php,dry,fpdf,isset,Php,Dry,Fpdf,Isset,有没有办法“擦干”(不要重复)这段代码,或者我需要所有这些“isset”行?我有很多项目要处理就像这一个,只有当他们被选中。我正在使用FPDF。如果可能的话,我真的很想缩短处理器代码!:) } 单击查看完整尺寸 XS 性虐待 医学博士 LG 总件数 我可能还有几十个项目…是的,它被称为循环 function existQty(){ $flag = false; for ($i = 0 ; $i<6 ; $i++){ if ( isset($_POST

有没有办法“擦干”(不要重复)这段代码,或者我需要所有这些“isset”行?我有很多项目要处理就像这一个,只有当他们被选中。我正在使用FPDF。如果可能的话,我真的很想缩短处理器代码!:)

}


单击查看完整尺寸
XS
性虐待
医学博士
LG
总件数






我可能还有几十个项目…

是的,它被称为循环

function existQty(){
    $flag = false;
    for ($i = 0 ; $i<6 ; $i++){
     if ( isset($_POST["item3lQty"][$i]) && !empty($_POST["item3lQty"][$i]) ){
          flag = true;
          break;
       }
    }
    return flag;
}

function Item3l() {
   if (existQty()){
   $item3lQty = $_POST['item3lQty'];
   $itm3l     = $_POST['itm3l'];
   $des3l     = $_POST['des3l'];
   $clr3l     = $_POST['clr3l'];
   $this->SetFont('Arial', '', 10);
   $this->SetFillColor(242);
   $this->SetLineWidth(1); 
   $this->SetX(33);
   $this->Cell(97, 20, $itm3l, 'LRB', 0, 'L');
   $this->Cell(300, 20, $des3l, 'LRB', 0, 'L');
   $this->Cell(95, 20, $clr3l, 'LRB', 0, 'L');     
   for ($i = 0 ; $i < 6 ; $i++){
      $this->Cell(28, 20, $item3lQty[$i], 'LRB', 0, 'C');
   }
$this->Cell(28, 20, '', 'LRB', 0, 'C');
$this->Cell(38, 20, array_sum($item3lQty), 'LRB', 1, 'C');
}
函数existQty(){
$flag=false;
对于($i=0;$iSetFont('Arial','',10));
$this->SetFillColor(242);
$this->SetLineWidth(1);
$this->SetX(33);
$this->Cell(97,20,$itm3l,'LRB',0,'L');
$this->Cell(300,20,$des3l,'LRB',0,'L');
$this->Cell(95,20,$clr3l,'LRB',0,'L');
对于($i=0;$i<6;$i++){
$this->Cell(28,20,$item3lQty[$i],'LRB',0,'C');
}
$this->Cell(28,20,,'LRB',0,'C');
$this->Cell(38,20,数组和($item3lQty),'LRB',1,'C');
}

如果您使用的是
!empty
,则不需要
isset
。如果它不是空的,则必须设置它。
这意味着empty()本质上是与!isset($var)| |$var==false的简明等价物。
您可以使用循环来迭代
item3lQty
。要改进您的工作代码,请访问
$\u POST[“item3lQty”][i]
应该是
$\u POST[“item3lQty”][$i]
谢谢!:)但是现在在PDF创建代码的开头出现错误
$PDF=new PDF\u receive()PHP解析错误:语法错误、意外的“$pdf”(T_变量)、预期的函数(T_函数)或常量(T_常量),那么为什么您的错误与此函数相关?:)尝试粘贴您的PDF_收据类
<fieldset class="item-fieldset" form="itemsForm">
<legend><?php echo $itm3l ?></legend>   

<div class="item_image_container">  
<a href="<?php echo $img3l_full_lnk ?>" target="_blank">
<img class="item_image" src="<?php echo $img3l_82px_lnk ?>" /></a>
<span class="click_full_image">Click for full size</span>
</div><!-- ITEM_IMAGE div CLOSE --> 

<table class="inputs" border="1" cellspacing="1">
<tbody>
<tr class="gridaddrows">
<td colspan="8" class="radius">
<div class="itemdesc"><?php echo $des3l ?></div>
</td>
</tr>
<tr class="gridrows">
<td class="gridtitle">XS</td>
<td class="gridtitle">SM</td>
<td class="gridtitle">MD</td>
<td class="gridtitle">LG</td>
<td class="gridtitle"></td>
<td class="gridtitle"></td>
<td class="gridtitle">Total Pcs</td>
</tr>
<tr>
<input type="hidden" name="itm3l" value='<?php echo $itm3l ?>'>
<input type="hidden" name="des3l" value='<?php echo $des3l ?>'>
<input type="hidden" name="clr3l" value='<?php echo $clr3l ?>'>
<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off"><br>
<span class="price"><?php echo $price3l ?></span></td>

<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off"><br>
<span class="price"><?php echo $price3l ?></span></td>

<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off"><br>
<span class="price"><?php echo $price3l ?></span></td>

<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off"><br>
<span class="price"><?php echo $price3l ?></span></td>

<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off" style="visibility: hidden"><br>
<span class="price" style="visibility: hidden"><?php echo $price3l ?></span></td>

<td><input type="number" class="item3l" min="0" max="288" name="item3lQty[]" placeholder="Qty" autocomplete="off" style="visibility: hidden"><br>
<span class="price" style="visibility: hidden"><?php echo $price3l_xx ?></span></td>

<td><input type="number" class="item3ltotal" value="" readonly/></td>
</tr>
</tbody>
</table>        
</fieldset>
function existQty(){
    $flag = false;
    for ($i = 0 ; $i<6 ; $i++){
     if ( isset($_POST["item3lQty"][$i]) && !empty($_POST["item3lQty"][$i]) ){
          flag = true;
          break;
       }
    }
    return flag;
}

function Item3l() {
   if (existQty()){
   $item3lQty = $_POST['item3lQty'];
   $itm3l     = $_POST['itm3l'];
   $des3l     = $_POST['des3l'];
   $clr3l     = $_POST['clr3l'];
   $this->SetFont('Arial', '', 10);
   $this->SetFillColor(242);
   $this->SetLineWidth(1); 
   $this->SetX(33);
   $this->Cell(97, 20, $itm3l, 'LRB', 0, 'L');
   $this->Cell(300, 20, $des3l, 'LRB', 0, 'L');
   $this->Cell(95, 20, $clr3l, 'LRB', 0, 'L');     
   for ($i = 0 ; $i < 6 ; $i++){
      $this->Cell(28, 20, $item3lQty[$i], 'LRB', 0, 'C');
   }
$this->Cell(28, 20, '', 'LRB', 0, 'C');
$this->Cell(38, 20, array_sum($item3lQty), 'LRB', 1, 'C');
}