【发布时间】:2015-07-27 03:32:07
【问题描述】:
我有一个这样显示的数组:
echo '<table>';
foreach ($rowData as $row => $tr) {
echo '<tr>';
foreach ($tr as $td)
echo '<td>' . $td .'</td>';
echo '</tr>';
}
echo '</table>';
第二列和第四列始终是列的名称。结果是这样的:
姓名:John Locke - 昵称:Locke
年龄:20 - 地址:好的
看到图案了吗?
如何将这些数组放入我的数据库中?
因为我的数据库表结构是:
ID - Name - NickName - Age - Adress
我不知道如何处理我正在使用的数组..
--更新
$table = $html->find('table', 0);
$rowData = array();
foreach($table->find('tr') as $row) {
// initialize array to store the cell data from each row
$flight = array();
foreach($row->find('td') as $cell) {
foreach($cell->find('span') as $e){
$e->innertext = '';
}
// push the cell's text to the array
$flight[] = $cell->plaintext;
}
$rowData[] = $flight;
}
echo '<table>';
foreach ($rowData as $row => $tr) {
echo '<tr>';
echo '<td>' . $row . '</td>';
foreach ($tr as $td)
echo '<td>' . $td .'</td>';
echo '</tr>';
}
echo '</table>';
【问题讨论】: