回覆列表
-
1 # 小雞戰場
-
2 # 泰迪神蹟
$a=array("h1","h2","h3");
$b=array("c1","c2","c3");
for($a as $key => $value)
{
echo $value . $b[$key];
}
$a=array("h1","h2","h3");
$b=array("c1","c2","c3");
for($a as $key => $value)
{
echo $value . $b[$key];
}
php foreach 語法上是不可以同時遍歷2個數組的,只能遍歷一個數組。程式碼如下:<?php$array1 = array(0=>"a",1=>"b");foreach($array1 as $key1=>$value1){ echo $key1.":".$value1."<br>";}?>不過,如果這2個數組有相同的鍵名的話,可以同時遍歷。程式碼如下:<?php$array1 = array(0=>"a",1=>"b");$array2= array(0=>"c",1=>"d");foreach($array1 as $key1=>$value1){ echo "陣列1 ".$key1.":".$value1."<br>"; echo "陣列2 ".$key1.":".$array2[$key1]."<br>";}