2017-04-21 42 views
0

我有数据的像阵列:我如何操纵json编码数据的数组?

Array 
(
    [0] => Array 
     (
      [lot_no] => ["A001","A001","B002"] 
      [qty] => ["4","5","6"] 
      [weight] => ["4","5","6"] 
      [particular] => ["100% cashmere","100% cashmere","20% silk 80% cashmere"] 
      [remarks] => ["4","5","6"] 
     ) 

) 

我想扔在PIC表中没有1像第二PIC的示于表该数据。我怎样才能做到这一点? table no 1 Table 2

+0

不清楚的问题..解释细节 –

+0

你的问题我想如上图所示,图一 扔在桌子lot_no的值,但我已经在上面的图二所示表 – Xravn

回答

0

可以遍历数组的循环鉴于

<?php if (count($detailListDatas) > 0): ?> 
    <table> 
     <thead> 
     <tr> 
      <th>Sno</th> 
      <th>Particular</th> 
      <th>Lot no</th> 
      <th>Total Qty</th> 
      <th>Total Weight</th> 
      <th>Remark</th> 
      <th>Action</th> 
     </tr> 
     </thead> 
     <tbody> 
    <?php $i=0; 
      foreach ($detailListDatas as $row) ?> 
     <tr> 
      <td><?php echo $i++?></td> 
      <td><?php echo $row['particular']; ?></td> 
      ... similarly all the element 
     </tr> 
    <?php endforeach; ?> 
     </tbody> 
    </table> 
    <?php endif; ?> 
+0

不,它没有帮我出 – Xravn

+0

什么是错误? –

+0

current()期望参数1为数组,字符串为 array_keys()期望参数1为数组,空给出 – Xravn

0

我想你的答案,也没有给我我所需要的输出。最终我做到了我自己这样

  <table class="table table-bordered table-striped"> 
        <thead> 
         <tr> 
          <th>S.No</th> 
          <th>Particulars</th> 
          <th>Lot no</th> 
          <th>Total Qty</th> 
          <th>Total Weight</th> 
          <th>Remarks</th> 
         </tr> 
        </thead> 
        <tbody> 
          <?php $sn =1; 
           foreach ($detailListDatas as $key) { 
            $json_array['lot_no'] = json_decode($key['lot_no'], true); 
            $lot_no = $json_array['lot_no']; 
            $i = count($lot_no); 
            $json_array['qty'] = json_decode($key['qty'],true); 
            $qty = $json_array['qty']; 
            $json_array['weight'] = json_decode($key['weight'],true); 
            $weight = $json_array['weight']; 
            $json_array['particular'] = json_decode($key['particular'],true); 
            $particular = $json_array['particular']; 
            $json_array['remarks'] = json_decode($key['remarks'],true); 
            $remarks = $json_array['remarks']; 
            for ($j=0; $j < $i ; $j++) { ?> 
             <tr> 
              <td><?php echo $sn?></td> 
              <td><?php echo $particular[$j];?></td> 
              <td><?php echo $lot_no[$j];?></td> 
              <td><?php echo $qty[$j];?></td> 
              <td><?php echo $weight[$j];?></td> 
              <td><?php echo $remarks[$j];?></td> 
             </tr> 
           <?php $sn++; } ?> 
           <?php } ?> 
        </tbody> 
       </table> 
+0

请最低限度地选择您的代码,以减少不必要的滚动,并提供一些解释与您的代码,以便将来的SO读者可以受益。 (您的答案在低质量的审核队列中。) – mickmackusa