$multidim_arr = array
(
array
(
0 => 1374,
1 => 223
),
array
(
0 => 1540,
1 => 224
),
array
(
0 => 1541,
1 => 225
)
);
$n = count($multidim_arr);
$z = count($multidim_arr[$n-1]);
echo "<table>";
for($j = 0; $j<$z;$j++) {
echo "<tr>";
for($i = 0; $i<$n; $i++) {
echo "<td>".$multidim_arr[$i][$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
首先在 PDO 中做 PDO::FETCH_NUM 而不是 PDO::FETCH_BOTH 检查http://php.net/manual/en/pdostatement.fetch.php
问候
@edit 或使用键:
<?php
$multidim_arr = array
(
array
(
'id' => 1374,
'version_id' => 223
),
array
(
'id' => 1540,
'version_id' => 224
),
array
(
'id' => 1541,
'version_id' => 225
)
);
$n = count($multidim_arr);
$z = count($multidim_arr[$n-1]);
$keys = array_keys($multidim_arr[$n-1]);
echo "<table>";
for($j = 0; $j<$z;$j++) {
echo "<tr>";
for($i = 0; $i<$n; $i++) {
echo "<td>key: ".$keys[$j]." and value: ".$multidim_arr[$i][$keys[$j]]."</td>";
}
echo "</tr>";
}
echo "</table>";
@edit 另一个例子
<?php
$multidim_arr = array
(
array
(
0 => 1374,
'id' => 1374,
1 => 223,
'version_id' => 223
),
array
(
0 => 1540,
'id' => 1540,
1 => 224,
'version_id' => 224
),
array
(
0 => 1541,
'id' => 1541,
1 => 225,
'version_id' => 225
)
);
$n = count($multidim_arr);
$z = count($multidim_arr[$n-1])/2;
$keys = array('id', 'version_id');
echo "<table>";
for($j = 0; $j<$z;$j++) {
echo "<tr>";
for($i = 0; $i<$n; $i++) {
echo "<td>key: ".$keys[$j]." and value: ".$multidim_arr[$i][$keys[$j]]."</td>";
}
echo "</tr>";
}
echo "</table>";
但在这里你必须知道钥匙。