将PHP数组切片到表中
不确定“slice”是否是正确的词。。但是,我将以下数组存储在变量中将PHP数组切片到表中,php,arrays,Php,Arrays,不确定“slice”是否是正确的词。。但是,我将以下数组存储在变量中 Array ( [0] => Design|1-cylinder 4-stroke engine, water-cooled [1] => Displacement|373.2 cm³ [2] => Bore|89 mm [3] => Stroke|60 mm [4] => Performance|32 kW (43 hp) [5] => Starting aid|Electric star
Array (
[0] => Design|1-cylinder 4-stroke engine, water-cooled
[1] => Displacement|373.2 cm³
[2] => Bore|89 mm
[3] => Stroke|60 mm
[4] => Performance|32 kW (43 hp)
[5] => Starting aid|Electric starter
[6] => Transmission|6 speed, claw shifted
[7] => Engine lubrication|Wet sump
) 1
请注意分隔内容的“|”。此内容应位于这样的表中
<table>
<thead>
<tr>
<td>Title</td>
<td>Details</td>
</tr>
</thead>
<tbody>
<tr>
<td>Engine Displacement</td>
<td>373.2 cm³</td>
</tr>
<tr>
<td>Transmission</td>
<td>6 speed, claw shifted</td>
</tr>
</tbody>
</table>
标题
细节
发动机排量
373.2立方厘米
传输
6速度,爪移动
我如何编写一个foreach语句来实现这一点?我甚至不知道从哪里开始?我应该分开阵列吗?不确定
提前谢谢 $aData=数组(
$aData = array(
'Design|1-cylinder 4-stroke engine, water-cooled',
'Displacement|373.2 cm³',
'Bore|89 mm',
'Stroke|60 mm',
'Performance|32 kW (43 hp)',
'Starting aid|Electric starter',
'Transmission|6 speed, claw shifted',
'Engine lubrication|Wet sump'
);
?>
<table>
<thead>
<tr>
<th>Title</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<?php
$iCountData = count( $aData );
for( $i = 0; $i < $iCountData; ++$i )
{
$aTmp = explode( '|', $aData[ $i ] );
echo '<tr>';
echo '<td>';
echo $aTmp[ 0 ];
echo '</td>';
echo '<td>';
echo $aTmp[ 1 ];
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
“设计| 1缸4冲程发动机,水冷式”,
“位移| 373.2 cm³”,
“孔径| 89毫米”,
“行程| 60 mm”,
“性能| 32千瓦(43马力)”,
“起动辅助装置|电启动器”,
“变速箱| 6速,爪移”,
“发动机润滑|湿油底壳”
);
?>
标题
细节
Wow可能会寻找更多的解释,但是你写的整个代码块太棒了!现在明白了,非常感谢你!