【发布时间】:2015-11-09 14:25:48
【问题描述】:
我有如下多维关联数组
sr_array=>
array (size=18)
0 => string 'Shop' (length=4)
1 => string 'Papu Kushwaha' (length=13)
2 => string 'Jitendra Shukla' (length=15)
3 => string 'Satish' (length=6)
4 => string 'Pradeep' (length=7)
5 => string 'Papu Khan' (length=9)
6 => string 'Bharat' (length=6)
7 => string 'Manoj Pandey' (length=12)
8 => string 'select' (length=6)
'Shop' =>
array (size=9)
'count_auto' => int 60
'count_indus' => int 4
'count_mc' => int 100
'count_inverter' => int 10
'count_in_bat' => int 40
'total_credit' => int 191850
'sale_value' => int 1351755
'total_disc' => float 22377.38
'perc_disc' => float 1.66
等等……
现在我想以表格格式打印它们,我使用以下代码进行输出
echo"<table border=1>";
echo"<tr>";
echo"<th></th>";
for($i=0; $i < count($sr_array)/2; $i++){
$current_sr = $sr_array[$i];
echo"<th>{$current_sr}</th>";
}
echo"</tr>";
$keys = array_keys($sr_array);
for($i=0; $i < count($sr_array)/2; $i++){
$current_sr = $sr_array[$i];
echo"<tr>";
echo"<td></td>";
foreach($sr_array as $key => $var){
foreach($var as $x => $y)
echo"<td>{$y["count_auto"]}</td>";
}
echo"</tr>";
}
请帮我出去
-------------------------------------
| |Shop |xyz |abc |
-------------------------------------
count_auto |60 |75 | 85 |
-------------------------------------
count_indus | 25 | 74 |15 |
--------------------------------------
count_mc | 55 | 212 | 15 |
-------------------------------------
等等
我收到错误为 foreach() 提供的参数无效
提前致谢
【问题讨论】:
标签: php loops multidimensional-array foreach associative-array