Dubstaphone
Dubstaphone

Reputation: 420

How do I echo the contents of 2 different arrays?

The question may have been unclear, but it requires a bit of explaining, so here goes:

I have 2 arrays: $friendsarr and $friendunamearr. $friendarr holds the ID's of the users on the user's friends list, and $friendunamearr holds their username. I've already echoed their usernames using the following code:

$funameimp = implode('<br />', $friendunamearr);
echo($funameimp);

But I want to turn these into links. For example:

echo('<a href="../../profile?id=' . $somebodysID . '>' . $funameimp . '</a>');

I heard something about "foreach," but I have no idea what to do.

All help is appreciated.

Upvotes: 0

Views: 53

Answers (1)

Expedito
Expedito

Reputation: 7795

If the arrays are keyed the same you can do it like this:

foreach ($friendarr as $key => $value){
    echo '<a href="../../profile?id=' . $value . '>' . $friendunamearr[$key] . '</a>';
}

Upvotes: 1

Related Questions