嵌套关联数组打印为表格


Nested Associative Arrays printed as a Table

下午好。我是php的新手,所以如果我的问题对这个论坛来说有点简单,请提前道歉。

我有一个PHP关联数组,其中包含一些嵌套的子数组,我希望将其作为表进行回显。这是阵列:

Array 
    ( 
    [message] => Your request was executed successfully. 
    [errors] => [warnings] => Array ( ) 
    [request_timestamp] => 04-08-2016 21:43:06 
    [response_timestamp] => 04-08-2016 21:43:06 
    [request_id] => abcd1234 
    [branch] => Array 
            ( 
            [location_id] => 157499 
            ) 
    [property] => Array 
            ( 
                    [0] => Array 
                    ( 
                    [agent_ref] => WR37EF-453625 
                    [update_date] => 
                    [client_id] => 60462053 
                    [channel] => 2
                    )
                    [1] => Array 
                    ( 
                    [agent_ref] => Prop950 
                    [update_date] => 04-08-2016
                    [client_id] => 60457613 
                    [channel] => 2 
                    ) 
                    [prop2] => Array 
                    ( 
                    [agent_ref] => WR40rp-632482 
                    [update_date] => 04-08-2016
                    [client id] => 60461789 
                    [channel] => 2 
                    ) 
                    [prop3] => Array 
                    ( 
                    [agent_ref] => WR38UU-243564 
                    [update_date] => 04-08-2016
                    [id] => 60461807 
                    [channel] => 2 
                    ) 
                    [prop4] => Array 
                    (
                    [agent_ref] => WR3HMWR3HM-145622 
                    [update_date] => 04-08-2016
                    [client id] => 60462014 
                    [channel] => 2 
                    ) 
            ) 
    )

我正在尝试(但不幸未能实现)的是以下格式的表格(前面有一个非表格标题区域)。。。。

标题区域:-

  1. 消息:您的请求已成功执行
  2. 错误:a、b、c
  3. 请求时间戳:2016年4月8日21:43:06
  4. 响应时间戳:2016年4月8日21:43:06
  5. 请求id:abcd1234
  6. 客户id:157499

然后是

表格设计,其中:-

  1. 。。行是子数组名称:[0];[1] ;[2] ;[3]
  2. 。。列标题名称是子数组$keys:agent_ref;更新日期;客户端id;通道
  3. 。。行col值是子数组$values

我知道我可能需要使用foreach循环方法。但是,以我需要的标题/表格格式从嵌套数组中取出键值对,我真的很难。

任何帮助或指导都将不胜感激。

感谢

类似这样的东西:

<?php
extract($your_array);
echo "$message<br>";
echo "$request_id<br>"; ...etc.
..

$first=true;
echo "<table>";
foreach($property as $propkey=>$propdets) {
  if ($first) { // on first row - do headings
    $heads=array_keys($propdets); // gets the keys for headings
    echo "<tr><th>Item</th>";
    foreach($heads as $hdng) {
      echo "<th>$hdng</th>";
    }
    echo "</tr>";
  }
  $first=false;
  echo "<tr><td>$propkey</td>"; // first column is the key(Item) - 0,1,prop2,prop3 etc.
  foreach ($propdets as $pdet) { // then loop through the details
    echo "<td>$pdet</td>";
  }
  echo "</tr>";
}
echo "</table>";
...
...
?>