douliang9057 2016-06-23 05:39
浏览 52

访问数组在PHP中多维主从元素

I have array Multidimention, that i designed to master to detail information.

This array Looked like this :

Array
(
[BSIU2473289] => Array
    (
        [0] => Array
            (
                [ID_BARANG] => 13649
                [THICK] => 0.70
                [SIZE] => 0.70MM X 151.8MM    
                [COIL_NO] => 02NKXTL16064945/48            
                [NET] => 2772
                [GROSS] => 2808
                [CONTRACT_NO] => N512C56LJ02         
                [LOCATION] => 
                [NO_URUT] =>   5785
            )

        [1] => Array
            (
                [ID_BARANG] => 13657
                [THICK] => 0.70
                [SIZE] => 0.70MM X 151.8MM    
                [COIL_NO] => 02NKXTL16065029/36            
                [NET] => 3512
                [GROSS] => 3552
                [CONTRACT_NO] => N512C56LJ02         
                [LOCATION] => 
                [NO_URUT] =>   5784
            )

        )
  )

I want to create a report based this array :

REPORT DUMMY

No : BSIU2473289

CONTAINS :  

[ID_BARANG] => 13649
[THICK] => 0.70
[SIZE] => 0.70MM X 151.8MM    
[COIL_NO] => 02NKXTL16064945/48            
[NET] => 2772
[GROSS] => 2808
[CONTRACT_NO] => N512C56LJ02         
[LOCATION] => 
[NO_URUT] =>   5785
[CONTAINER] => BSIU2473289

So on, so on.

How can I make the looping like this ?

<?php foreach ($result as $row): ?>
  <div class="container">
    <div class="header" >
      <!--<img src="D:\xampp\htdocs\develop_tsurumaru\assets\admin\img\logo_tli_web.png">-->
      <!-- <img src="./assets/admin/img/logo_tli_web.jpg"> -->
    </div>

    <div class="document-title"  style='margin-top : 120px;'>
      <hr>
      <h1>Check List<br>Check Sheet for PT. Hanwa Indonesia </h1>
    </div>



    <div class="master" style="width: 40%; display: inline-block">
      <table class="table" style="border: none;">

        <tr style="border:none">
          <td style="height:20px; border: none; text-align: left; width: 30%;">Container No</td>
          <td style="border: none; width:5%;">: </td>
          <td style="border: none; text-align: left; vertical-align: middle;"><?php echo BSIU243289 ?></td>
        </tr>



      </table>
    </div>

    <div style="padding-top : -100px" >
      <table>
        <thead>
          <tr>
            <th rowspan="2">NO</th>
            <th rowspan="2" style="width: 20%">SIZE</th>
            <th rowspan="2" style="width: 18%">CODE OF COIL</th>
            <th rowspan="2">WGHT (NET)</th>
            <th rowspan="2">WGHT (GROSS)</th>
            <th rowspan="2"style="width: 8%">CONTRACT NO</th>
            <th rowspan="2">LOCATION</th>
            <th colspan="3">DENT</th>
            <th rowspan="2">WET</th>
            <th rowspan="2" style="font-size: smaller">NO<br>DMG</th>
            <th rowspan="2">OTH</th>
            <th rowspan="2">NO URUT</th>
          </tr>

          <tr>
            <th style="width: 3%">In</th>
            <th style="width: 3%">Out</th>
            <th style="width: 3%">End</th>
          </tr>

        </thead>

        <tbody>
          <?php
          $i = 1;
          $total_net = 0;
          $total_gross = 0;
          ?>

          <?php foreach ($row as $key => $value) : ?>
            <?php
            echo "<tr>";
            echo "<td>$i</td>";
            echo "<td>". $value['SIZE'] . "</td>";
            echo "<td>". $value['COIL_NO'] . "</td>";
            echo "<td>". $value['NET'] . "</td>";
            echo "<td>". $value['GROSS'] . "</td>";
            echo "<td>". $value['CONTRACT_NO'] . "</td>";
            echo "<td>". $value['LOCATION'] . "</td>";
            echo "<td></td>";
            echo "<td></td>";
            echo "<td></td>";
            echo "<td></td>";
            echo "<td></td>";
            echo "<td></td>";
            echo "<td>". $value['NO_URUT'] . "</td>";
            echo "</tr>";

            $total_net += $value['NET'];
            $total_gross = $value['GROSS'];
            $i++;
            ?>
          <?php endforeach;  ?>

          <tr>
            <td colspan="3">Total :</td>
            <td><?= $total_net ?></td>
            <td><?= $total_gross ?></td>
            <td colspan="9"></td>
          </tr>

        </tbody>
      </table>
    </div>


        </tbody>

      </table>
  </div>
</body>
  • 写回答

3条回答 默认 最新

  • dpgu5074 2016-06-23 06:15
    关注

    Please check following code .

    <?php
    
    $arr = Array
    (
    'BSIU2473289' => Array
        (
            0 => Array
                (
                    'ID_BARANG' => '13649',
                    'THICK' => '44',
                    'SIZE' => '0.70MM X 151.8MM'   , 
                    'COIL_NO' => '02NKXTL16064945/48' ,           
                    'NET' => '2772',
                    'GROSS' => '2808',
                    'CONTRACT_NO' => 'N512C56LJ02'      ,   
                    'LOCATION' => '',
                    'NO_URUT'=>   '5785'
                ),
    
            1 => Array
                (
                    'ID_BARANG'=> '13657',
                    'THICK' => '0.70',
                    'SIZE'=> '0.70MM X 151.8MM' ,   
                    'COIL_NO' => '02NKXTL16065029/36' ,           
                    'NET' => '3512',
                    'GROSS' => '3552',
                    'CONTRACT_NO' => 'N512C56LJ02'  ,       
                    'LOCATION' =>'' ,
                    'NO_URUT' =>   '5784'
                )
    
            ),
      );
    
    
    
    $first_key =  key($arr);
    foreach ($arr[$first_key] as $key => $value) {
    
        $chunk = $arr[$first_key][$key];
        foreach ($chunk as $key1 => $value) {
            echo  $arr[$first_key][$key][$key1]."<br>";
        }
    }
    
    
        ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法