php PHP表两列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13153263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:51:23 来源:igfitidea点击:
PHP table two columns
提问by MahmoudMustafa
How can I make table in PHP with two columns and 10 variables for example (without loop)?
例如,如何在 PHP 中制作包含两列和 10 个变量的表格(无循环)?
For example:
例如:
$var1= $row['name'];
$var2= $row['age'];
The way I want to show it in the table:
我想在表格中显示它的方式:
______________________
| Customer Name | $var1|
| Customer Age | $var2|
回答by Mihai Matei
Without loop:
无循环:
echo '
<table>
<tr>
<td>Customer Name</td>
<td>', $var1, '</td>
</tr>
<tr>
<td>Customer Age</td>
<td>', $var2, '</td>
</tr>
<tr>
<td>Customer ...</td>
<td>', $var3, '</td>
</tr>
</table>';
With foreach loop
使用 foreach 循环
$myFields = array("Customer Name" => $row['Name'],
"Customer Age" => $row['Age']);
echo '<table><tr>';
foreach($myFields as $field_title => $field_value)
echo '<td>', $field_title, '</td>
<td>', $field_value, '</td>';
echo '</tr></table>';
回答by Praveen Kumar Purushothaman
Simple. Use this syntax:
简单的。使用以下语法:
<table >
<tr>
<th>Customer Name</th>
<td><?php echo $var1; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var2; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var3; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var4; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var5; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var6; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var7; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var8; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var9; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var10; ?></td>
</tr>
</table>
回答by Praveen Kumar Purushothaman
You can use something like this:
你可以使用这样的东西:
$array = array();
$array[0]["name"];
$array[0]["age"];
or instead of that , you can use a loop:
或者代替那个,您可以使用循环:
$i=0;
while($i<10){
$array[$i]["name"]=...;
$i++;
}
print_r($array);

