dougu4704 2013-06-10 20:46
浏览 18
已采纳

如何回显2个不同数组的内容?

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.

  • 写回答

1条回答 默认 最新

  • dongtazu3080 2013-06-10 20:51
    关注

    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>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?