dsl2014 2018-02-05 10:47
浏览 23
已采纳

将序列号指定为html的ID

I'm sorry for asking similar question again, but I wanted to make my question short and because of this, your solutions doesn't work for me (I thought it will work in similar way in arrays).

I'm getting photos from xml file:

$filelocation=simplexml_load_file('http://path.com/file.xml');
foreach($filelocation->path->attributes() as $photo) {
$position[$flag1]["photos"] .=  "<a id=\"carousel-selector-".$dont-know-what-to-do-here."\"><img src=\"".$photo."\"/></a>";
}

It's of course a part of the code which shows photos placed in xml file. What I need is to place unique id to all of them so it will work like:

<a id="carousel-selector-0"><img src="http://path.com/link.jpg"/></a>
<a id="carousel-selector-1"><img src="http://path.com/another-link.jpg"/></a>
...

Can you help me with that?

  • 写回答

3条回答 默认 最新

  • douchi0471 2018-02-05 10:52
    关注

    You've to maintain the index for each iteration, as we don't know what will be the key, so that we can maintain index outside and will increase the index each time.

    $filelocation=simplexml_load_file('http://path.com/file.xml');
    $index = 0;
    foreach($filelocation->path->attributes() as $photo) {
    $position[$flag1]["photos"] .=  "<a id=\"carousel-selector-".$index."\"><img src=\"".$photo."\"/></a>";
    $index++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline