Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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-迭代数组并在HTML表中转置数组数据_Php_Arrays_Iteration - Fatal编程技术网

PHP-迭代数组并在HTML表中转置数组数据

PHP-迭代数组并在HTML表中转置数组数据,php,arrays,iteration,Php,Arrays,Iteration,我有点困了,需要你的帮助!我有一批学生: 学生: 我迭代了每个学生(这里没有问题…),对于每个学生,我有他们两周的用餐时间表(在下面的数组中,我有约翰(仅)从3月31日到4月13日的时间表---杰瑞、山姆和阿曼达的时间表结构相同,但值不同等等) 用餐时间: ) 这就是我被困的地方-- 我需要的布局如下: 同样的期望输出也会显示给其他三个学生。。。根据他们自己的用餐时间表 我已经研究过了,在这个网站或网上还没有遇到类似的情况 我如何才能做到这一点?非常感谢您的任何帮助 谢谢 <table

我有点困了,需要你的帮助!我有一批学生:

学生:

我迭代了每个学生(这里没有问题…),对于每个学生,我有他们两周的用餐时间表(在下面的数组中,我有约翰(仅)从3月31日到4月13日的时间表---杰瑞、山姆和阿曼达的时间表结构相同,但值不同等等)

用餐时间:

)

这就是我被困的地方--

我需要的布局如下:

同样的期望输出也会显示给其他三个学生。。。根据他们自己的用餐时间表

我已经研究过了,在这个网站或网上还没有遇到类似的情况

我如何才能做到这一点?非常感谢您的任何帮助

谢谢


<table>
   <tr>
       <?php foreach ($johnArray as $date=>$food) { ?>
       <td><?= date('m/d', strtotime($date)) ?></td>
       <?php } ?>
       <td>Type</td>
   </tr>
   <!-- Apple row -->
   <tr>
       <?php foreach ($johnArray as $date=>$food) { ?>
       <td><?= $food['Apples'] ?></td>
       <?php } ?>
       <td>Apple</td>
   </tr>
</table>
类型 苹果
这只是帮助您入门的一个片段。您应该能够自己计算出其他行

这个例子是针对一个人的(我假设每个人都有自己的表)。 首先生成包含日期的第一行,然后是类型列。因此,可以循环遍历数组中的键日期,并为每个日期创建一列。然后添加类型的列


对食物值也采用相同的方法。

嵌套循环。行循环遍历水果,列循环遍历日期。@Barmar——任何代码示例都将不胜感激!所以这不是免费的编码服务。你必须自己尝试解决这个问题。如果你不能让它工作,张贴你尝试了什么,我们会帮助你解决它。这就是我一直在寻找的。。。正确方向的暗示;巴尔马的评论有点含糊。谢谢Prem Raj!
Array
(
[31-MAR-17] => Array
    (
        [Apples] => 1
        [Oranges] => 
        [Peaches] => 
        [Berries] => 
    )
[01-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 
        [Peaches] => 2
        [Berries] => 
    )

[02-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 2
        [Peaches] => 
        [Berries] => 
    )

[03-APR-17] => Array
    (
        [Apples] => 2
        [Oranges] => 
        [Peaches] => 2
        [Berries] => 
    )

[04-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 
        [Peaches] => 
        [Berries] => 50
    )

[05-APR-17] => Array
    (
        [Apples] => 1
        [Oranges] => 1
        [Peaches] => 1
        [Berries] => 
    )

[06-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 2
        [Peaches] => 
        [Berries] => 
    )

[07-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 
        [Peaches] => 
        [Berries] => 50
    )

[08-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 
        [Peaches] => 3
        [Berries] => 
    )

[09-APR-17] => Array
    (
        [Apples] => 3
        [Oranges] => 
        [Peaches] => 
        [Berries] => 20
    )

[10-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 2
        [Peaches] => 
        [Berries] => 15
    )

[11-APR-17] => Array
    (
        [Apples] => 
        [Oranges] => 
        [Peaches] => 1
        [Berries] => 20
    )

[12-APR-17] => Array
    (
        [Apples] => 2
        [Oranges] => 3
        [Peaches] => 
        [Berries] => 
    )

[13-APR-17] => Array
    (
        [Apples] => 1
        [Oranges] => 
        [Peaches] => 2
        [Berries] => 
    )
<table>
   <tr>
       <?php foreach ($johnArray as $date=>$food) { ?>
       <td><?= date('m/d', strtotime($date)) ?></td>
       <?php } ?>
       <td>Type</td>
   </tr>
   <!-- Apple row -->
   <tr>
       <?php foreach ($johnArray as $date=>$food) { ?>
       <td><?= $food['Apples'] ?></td>
       <?php } ?>
       <td>Apple</td>
   </tr>
</table>