如何从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表中,其中表中名为“links”的每一列已经对应于数组中的行名称(pos,place,title,picurl,picwidth,picheight,titleurl)。 。(在数据库插入之前已经预先填充了两个foreach循环)
尚不确定如何连接到数据库。谢谢。