我有以下数组
$consulta2 = Array (
[AB] => Array ( [0] => Noah [1] => 48 )
[BC] => Array ( [0] => Jacob [1] => 42 )
[DA] => Array ( [0] => Mason [1] => 27 )
)
我想在表中打印带有 KEYS 和 VALUES 的数组
我目前正在使用这个 foreach 循环
foreach ($consulta2 as $key => $value){
foreach ($value as $k => $v) {
$template.= '<tr>
<td class="service">'.$key.'</td>
<td class="desc">'.$v.'</td> \r \n
<td class="service">'.$v.'</td>
<td class="service"></td>
</tr>';
}
}
我得到下表
+-----+-------+-------+
| Key | Value | Value |
+-----+-------+-------+
| AB | Noah | Noah |
+-----+-------+-------+
| AB | 48 | 48 |
+-----+-------+-------+
| BC | Jacob | Jacob |
+-----+-------+-------+
| BC | 42 | 42 |
+-----+-------+-------+
| DA | Mason | Mason |
+-----+-------+-------+
| DA | 27 | 27 |
+-----+-------+-------+
但我希望它看起来像这样
+-----+-------+-------+
| Key | Value | Value |
+-----+-------+-------+
| AB | Noah | 48 |
+-----+-------+-------+
| BC | Jacob | 42 |
+-----+-------+-------+
| DA | Mason | 27 |
+-----+-------+-------+
如果有人知道如何解决它,我将非常感激
qq_笑_17