2017-04-21 43 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