0
如何可以創建從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循環預填充)
不確定如何連接到數據庫。謝謝。
你會知道如何結合兩個foreach循環來構建1個數組,並且暫時忘記插入請求嗎? – Adrian33 2013-04-06 19:01:03
我不太確定我完全理解你想要做什麼,但也許你想追加狗和貓的數組和'foreach'在附加數組上? – 2013-04-06 20:25:55
是的,狗+貓= ARR(我只是認爲最好通過騎自行車穿過狗,然後貓來建立ARR) – Adrian33 2013-04-06 21:47:24