如何从 2 个或多个 foreach 循环创建单个多维数组:
$arr = array();
//loop 1
foreach (dogs[1] as $key => $url)
{
$arr[$key]['pos'] = $key;
$arr[$key]['place'] = "2";
$arr[$key]['title'] = "3";
$arr[$key]['picurl'] = trim($dogs[2][$key]);
$arr[$key]['picwidth'] = "5";
$arr[$key]['picheight'] = "6";
$arr[$key]['titleurl'] = $url;
}
//loop 2
foreach (cats[1] as $key => $url)
{
$arr[$key]['pos'] = $key;
$arr[$key]['place'] = "2";
$arr[$key]['title'] = "3";
$arr[$key]['picurl'] = trim($cats[2][$key]);
$arr[$key]['picwidth'] = "5";
$arr[$key]['picheight'] = "6";
$arr[$key]['titleurl'] = $url;
}
然后将整个新的多维数组添加到 mysql 表中,其中表中称为“链接”的每一列已经对应于数组中的行名(pos、place、title、picurl、picwidth、picheight、titleurl)......(其中在插入数据库之前已由两个 foreach 循环预先填充)
不确定如何连接到数据库。谢谢你。