我有一个看起来像这样的数组:
$array = array(
"aceton" => "description here",
"acetonurie" => "description here",
"adipositas" => "description here",
"bolus" => "description here",
"cataract" => "description here",
"cortisol" => "description here",
);
接下来我使用数组数据构建一个定义列表:
<dl>
<?php foreach ($array as $key => $value): ?>
<dt><?php echo $key; ?><dd><?php echo $value; ?>
<?php endforeach; ?>
</dl>
这很好用,但我需要更多的东西。我需要一种方法来为每个唯一的首字母生成一个 id,因此结果变为:
<dl>
<dt id="a">aceton <dd>description here
<dt>acetonurie <dd>description here
<dt>adipositas <dd>description here
<dt id="b">bolus <dd>description here
<dt id="c">cataract <dd>description here
<dt>cortisol <dd>description here
et cetera..
</dl>
知道如何完成吗?