1 回答
TA贡献1818条经验 获得超3个赞
这是片段,
$ret = $html->find('tr');
$i = true;
$headers = [];
foreach ($ret as $key => $value) {
if ($i) {
// fetching headers of first row
foreach ($value->find('th') as $cell) {
$headers[] = $cell->plaintext;
}
} else {
$temp = [];
// fetching pending values of td
foreach ($value->find('td') as $cell) {
$temp[] = $cell->plaintext;
}
// combining headers with values fetched from not first row
$result[] = array_combine($headers, $temp);
}
$i = false;
}
print_r($result);die;
输出
Array
(
[0] => Array
(
[Satuan] => 0.5
[Harga Barang 1] => Rp 388.000
[Harga Barang 2] => Rp 342.000
[Harga Barang 3] => Rp 456.000
[Harga Barang 4] => Rp 377.000
)
[1] => Array
(
[Satuan] => 1.0
[Harga Barang 1] => Rp 725.000
[Harga Barang 2] => Rp 676.000
[Harga Barang 3] => Rp 855.000
[Harga Barang 4] => Rp 684.000
)
)
- 1 回答
- 0 关注
- 149 浏览
添加回答
举报