我正在构建一个基本的表单构建类,以加快我的工作流程,我希望能够像这样使用属性数组:
$attributes = array(
"type" => "text",
"id" => "contact-name",
"name" => "contact-name",
"required" => true
);
将其映射到HTML元素的属性:
<input type="text" id="contact-name" name="contact-name" required />
编辑:
如何以最简洁的方式实现上述内容?我相信我可以用循环和一些连接来拼凑出来,但我感觉printf或类似的方式可以更优雅地完成它。