我想从每 3 个单元格中取出索引为 0 的第一个单元格,第二个为 1,第三个为 2 并将其全部放入一个数组中,以便在 $ 结果 [0] 中的所有单元格值都是索引为 0 - 全部tr线等
<?
$lines = $xpath->query("//table[@id='cab_table'] //tr");
$result = array();
foreach($lines as $line) {
for($j=0; $j<=3; $j++) {
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$count = $tds_{$j}->length;
for($i=0; $i<$count; $i++){
$result['number'][] = $tds_{$j}->item($i)->nodeValue;
$result['volume'][] = $tds_{$j}->item($i)->nodeValue;
$result['code'][] = $tds_{$j}->item($i)->nodeValue;
}
}
?> }
HTML 代码:
<div class="pc-data-cab_table_block_container" style="overflow:auto">
<div id="cab_table_block" style="width:100%;overflow:auto">
<table id="cab_table" cellpadding="0px" cellspacing="0px" style="width:100%;overflow:auto">
<tr id="cab_table_tr_top">
<th id="cab_table_left">Номер счета</th>
<th>Объем</th>
<th id="cab_table_right">РЎСѓРјРјР° РєРѕРјРјРёСЃСЃРёРё</th>
</tr>
<tr class="cab_table_tr2">
<td class="cab_table_left1">510169</td>
<td style='width:130px'>0.04</td>
<td class="cab_table_right1">2.07</td>
</tr>
<tr class="cab_table_tr1">
<td class="cab_table_left1">1193683</td>
<td style='width:130px'>0.23</td>
<td class="cab_table_right1">0.00</td>
</tr>
<tr class="cab_table_tr2">
<td class="cab_table_left1">2159860</td>
<td style='width:130px'>1.06</td>
<td class="cab_table_right1">51.54</td>
</tr>
<tr class="cab_table_tr1">
<td class="cab_table_left1">8070080</td>
<td style='width:130px'>1.76</td>
<td class="cab_table_right1">147.80</td>
</tr>
<tr class="cab_table_tr2">
<td class="cab_table_left1">8079297</td>
<td style='width:130px'>19.25</td>
<td class="cab_table_right1">884.85</td>
</tr>
</table>
</div>
</div>