如何很好地显示数据结构。在下面粘贴我的多维数组,请帮助
Array
(
[1] => Array
(
[0] => Array
(
[LP] => 1
[Produkt] => product1
)
)
[2] => Array
(
[0] => Array
(
[LP] => 2
[number] => 157/03/2014
[Produkt] => product1
)
[1] => Array
(
[LP] => 2
[number] => 157/03/2014
[Produkt] => product2
)
)
)
===我的代码=========================================== ====
foreach ($a as $date) {
$output .= "\t\t\t<ID>". $date[0]['LP']."</ID>\n";
second foreach for product {
$output .= "\t\t\t<Produkt>". Produkt ."</Produkt>\n";
}
}
答案 0 :(得分:0)
我不确定我是否了解您想要做什么。 如果要写在屏幕上
foreach ($a as $date) {
foreach ($date as $product) {
$date_lp = $product['LP'];
if ($date_lp !== $last_date_lp) {
$last_date_lp = $date_lp;
$output .= "\t\t\t<ID>{$date_lp}</ID>\n";
}
$output .= "\t\t\t<Produkt>{$product['Produkt']}</Produkt>\n";
}
}
如果您打算将此数组转换为xml,则read this question关于将关联数组转换为xml。