我有三个PHP数组,我想在同一个循环中使用它们来获取值。
$advertising_advpic = "photo src1,photo src2,photo src3";
$advertising_advlink = "site link1,site link2,site link3";
$advertising_advtitle = "site name1,site name2,site name3";
$advpic = explode(",",$advertising_advpic);
$advlink = explode(",",$advertising_advlink);
$advtitle = explode(",",$advertising_advtitle);
for ( $i = 0; $i<count($advpic); $i++)
{
$link = $advlink [$i];
$pic = $advpic [$i];
$title = $advtitle[$i];
$all = "<td nowrap><a target='_blank' href='".$link."'><img src='".$pic."' border='0' alt='".$title."'></a></td>";
}
但是当我打印$all
时,我只得到最后一个值。
答案 0 :(得分:2)
试试这个
$advertising_advpic = "photo src1,photo src2,photo src3";
$advertising_advlink = "site link1,site link2,site link3";
$advertising_advtitle = "site name1,site name2,site name3";
$advpic = explode(",",$advertising_advpic);
$advlink = explode(",",$advertising_advlink);
$advtitle = explode(",",$advertising_advtitle);
$all = "";
for ( $i = 0; $i<count($advpic); $i++)
{
$link = $advlink[$i];
$pic = $advpic[$i];
$title = $advtitle[$i];
$all = $all . "<td nowrap><a target='_blank' href='".$link."'><img src='".$pic."' border='0' alt='".$title."'></a></td>";
}
你在循环的每一次迭代中不断重新获得$之前的方式。