3 回答
TA贡献1876条经验 获得超7个赞
编辑问题已更改
试试这个,我所做的是使用 2 个循环来获取数组的标题。另一个循环是显示结果。
$arr = [
'political' => [
0 => 'Krishna Colony',
1 => 'Police Head Quarters'
],
'locality' => [
0 => 'Chittorgarh ',
1 => 'Ratnagiri '
],
'administrative_area_level_2' => [
0 => 'Chittaurgarh ',
1 => 'Ratnagiri '],
'administrative_area_level_1' => [
0 => 'Rajasthan',
1 => 'Maharashtra '
],
'country' => [
0 => 'Chittorgarh ',
1 => 'Ratnagiri '
],
'street_number' => [
0 => 'India ',
1 => 'India '],
];
echo "<table id='table-loop' border='1'>";
$parent = [];
$total_count = 0;
echo "<tr>";
foreach ($arr as $a => $val) {
echo "<th>$a</th>";
array_push($parent, $a);
$total_count = count($val);
}
echo "</tr>";
$i = 0;
foreach ($arr as $a) {
if($i<$total_count){
echo "<tr>";
foreach($parent as $p){
echo "<td>". $arr[$p][$i]. "</td>";
}
echo "</tr>";
$i++;
}
}
echo "</table>";
结果将如下所示
TA贡献1818条经验 获得超3个赞
<?php
$a = [0 => 'Name1', 1 => 'Name2'];
$b = [0 => 'value1', 1 => 'value2'];
$c = [0 => 'age1', 1 => 'age2'];
$length = count($a);
echo '<table border="1">
<th>Name</th><th>Value</th><th>Age</th>';
for ($i = 0; $i < $length; $i++) {
echo '<tr><td>' . $a[$i] . '</td><td> ' . $b[$i] . ' </td><td>' . $c[$i] . '</td></tr>';
}
echo '</table>';
这些是有帮助的基本代码(当所有三个数组都具有相同的长度时)
TA贡献1828条经验 获得超3个赞
假设数组的名称分别是 $name、$value 和 $age,并假设每个数组的编号相同。价值观;
echo "<table><tr>";
for($i=1; $i<4; $i++) {
echo "<td>COL". $i . "</td>";
}
echo "</tr>";
for($i=0; $i<2; $i++) {
echo "<tr><td>". $name[$i] . "</td>";
echo "<td>". $value[$i] . "</td>";
echo "<td>". $age[$i] . "</td></tr>";
}
echo "</table>";
希望这可以帮助;
- 3 回答
- 0 关注
- 189 浏览
添加回答
举报