$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::FETCH_NUM を PDO で実行し、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>";
しかし、ここではキーを知っている必要があります。