0

I have three PHP arrays and I want to use them in the same loop to get the values.

$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>";
}

But when I print $all I only get the last value.

1 Answer 1

2

try this

$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>";
}

The way you had it before you were continually reassinging $all every iteration of the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.