将数组转换为另一个数组 [英] Convert array to another array
本文介绍了将数组转换为另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样显示的数组:
I have one array that I am showing like this:
echo '<table>';
foreach ($rowData as $row => $tr) {
echo '<tr>';
foreach ($tr as $td)
echo '<td>' . $td .'</td>';
echo '</tr>';
}
echo '</table>';
第二和第四列始终是该列的名称。结果是:
The second and fourth columns are always the name of the column. The result is something like:
姓名:John Locke-昵称:Lock
Name: John Locke - NickName: Locke
年龄:20-地址:好
看到图案了吗?
如何将这些数组放入数据库中?
How can I put these array in my database?
由于我的数据库表结构为:
As my database table structure is:
ID - Name - NickName - Age - Adress
我不知道如何使用我正在使用的数组。
I don't have a clue how to do that with the array i'm using..
-更新
$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>';
推荐答案
您可以这样做:
$insert = "";
foreach ($rowData as $row => $tr) {
$insert .= "('".$tr[0]."','".$tr[0]."','".$tr[0]."','".$tr[0]."'),";
}
$insert = substr($insert, 0, -1)
$sql = "Insert into YourTable values ".$insert;
这篇关于将数组转换为另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文