如何将关联数组映射到 html 元素属性?
我正在构建一个基本的表单构建类来加快我的工作流程,我希望能够采用如下属性数组:
$attributes = array(
"type" => "text",
"id" => "contact-name",
"name" => "contact-name",
"required" => true
);
并将其映射到 html 元素的属性:
<input type="text" id="contact-name" name="contact-name" required />
编辑:
实现上述目标的最干净的方法是什么?我确信我可以用一个循环和一些串联来拼凑一些东西,但我感觉printf或类似的东西可以以更优雅的方式做到这一点。