我已经为此苦苦挣扎了一段时间,但我根本无法弄清楚。这是我的代码:
<?php
$list = array(
"60002" => array("name" => "Cyan Bubble Color", "info" => array("cost" => "200", "code" => "0x50ebec")),
"65002" => array("name" => "Cyan Name Color", "info" => array("cost" => "150", "code" => "0x00cccc")),
);
foreach($list as $id =>$name) {
echo("<td style=\"vertical-align:middle;\">
<a href=\"item=$id#confirm\" role=\"button\" data-toggle=\"modal\">
Buy</a></td></tr>");
}?>
<html>
<div class="modal small hide fade" id="confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Log off before purchase</h3>
</div>
<div class="modal-body">
<p class="error-text"><i class="icon-warning-sign modal-icon"></i>Log off all instances</p>
</div>
<div class="modal-footer">
<a href="redeem.php?item=<?php echo $id; ?>"><button class="btn btn-danger">Buy</button></a>
</div>
这里的主要问题是来自 foreeach 的 $id 与 div 类链接中的 $id 不同。相反,链接是 foreach 列表的结束值。