duanan5940 2019-06-27 13:21
浏览 29
已采纳

PHP - 使用foreach显示2维数组

I would like to display a 2 dimension array. I tried to use a double foreach to make it but im a bit lost. It return's me an empty td and i dont know why. Im using ZendFramework. Should i use an other solution and leave the foreach solution or i just miss something ?

The array ( there is 7 arrays inside one array and the columns are always the same ) :

array(7) {
[0]=>
array(11) {
["'01.drplapostej-1'"]=>
string(20) "01. DRP La poste J-1"
["import"]=>
string(1) "0"
["radm_ok"]=>
string(1) "0"
["radm_rejet"]=>
string(1) "0"
["radm_ko"]=>
string(1) "0"
["rpec_ok"]=>
string(1) "0"
["rpec_rejet"]=>
string(1) "0"
["rpec_ko"]=>
string(1) "0"
["factu_ok"]=>
string(1) "0"
["factu_rejet"]=>
string(1) "0"
["factu_ko"]=>
string(1) "0"
}
[1]=>
array(11) {
["'01.drplapostej-1'"]=>
string(20) "02. DRL La poste J-1"
["import"]=>
string(2) "80"
["radm_ok"]=>
string(1) "0"
["radm_rejet"]=>
string(1) "0"
["radm_ko"]=>
string(1) "0"
["rpec_ok"]=>
string(1) "0"
["rpec_rejet"]=>
string(1) "0"
["rpec_ko"]=>
string(1) "0"
["factu_ok"]=>
string(1) "0"
["factu_rejet"]=>
string(1) "0"
["factu_ko"]=>
string(1) "0"
}

What i tried to do :

<table>
<tr>
<th>01.DRPLAPOSTEJ-1</th>
<th>IMPORT</th> 
<th>RADM_OK</th>
<th>RADM_REJET</th>
<th>RADM_KO</th>
<th>RPEC_OK</th>
<th>RPEC_REJET</th>
<th>RPEC_KO</th>
<th>FACTU_OK</th>
<th>FACTU_REJET</th>
<th>FACTU_KO</th>
</tr>
<?php foreach ($this->suiviprodjours as $value): ?>
  <?php foreach ($value as $key => $val): ?>
<tr>
<td <?php echo $val[$key]["01.DRPLAPOSTEJ-1"].'<br>';  ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>

The result :

enter image description here

  • 写回答

2条回答 默认 最新

  • dsijovl015728613 2019-06-27 13:29
    关注

    You need to apply foreach() like below:-

    <?php foreach($array as $arr){?>
        <tr>
            <?php foreach($arr as $value){?>
                <td><?php echo $value;?></td>
            <?php } ?>
        </tr>
    <?php } ?>
    

    So full code will be:

    <table>
        <tr>
            <th>01.DRPLAPOSTEJ-1</th>
            <th>IMPORT</th> 
            <th>RADM_OK</th>
            <th>RADM_REJET</th>
            <th>RADM_KO</th>
            <th>RPEC_OK</th>
            <th>RPEC_REJET</th>
            <th>RPEC_KO</th>
            <th>FACTU_OK</th>
            <th>FACTU_REJET</th>
            <th>FACTU_KO</th>
        </tr>
        <?php foreach($array as $arr){?>
            <tr>
                <?php foreach($arr as $value){?>
                    <td><?php echo $value;?></td>
                <?php } ?>
            </tr>
        <?php } ?>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题