我有 2 个数组,我想根据这些数组在我的表中自动创建新行。
我的数组看起来像这样:
$array1['name1'] = "value1";
$array1['name2'] = "value2";
$array1['nameN'] = "valueN";
$array2['name1'] = "number1";
$array2['name2'] = "number2";
$array2['nameN'] = "numberN";
我的 html 表格输出应如下所示:
<table>
<tr>
<td>name1</td>
<td>value1</td>
<td>number1</td>
</tr>
<tr>
<td>name2</td>
<td>value2</td>
<td>number2</td>
</tr>
<tr>
<td>nameN</td>
<td>valueN</td>
<td>numberN</td>
</tr>
</table>
我一直在研究这两个代码,但我不知道如何组合它们:
<?php
foreach ($array1 as $name => $value) {
echo '<tr><td>'.$name.'</td><td>'.$value.'</td></tr>';
};
unset($nick, $value);
?>
<?php
foreach ($array2 as $name => $value) {
echo '<tr><td>'.$name.'</td><td>'.$value.'</td></tr>';
};
unset($nick, $value);
?>
也许我可以将两个数组组合成一个多维数组并使用某种 foreach 函数,如下所示:
$array = array();
$array['name1']['array1'] = "value1";
$array['name1']['array2'] = "number1";
$array['name2']['array1'] = "value2";
$array['name2']['array2'] = "number2";
$array['nameN']['array1'] = "valueN";
$array['nameN']['array2'] = "numberN";
任何帮助将不胜感激!