rosavox/lib/alveolata/html/functions.php

62 lines
912 B
PHP
Raw Normal View History

2025-05-23 07:33:29 +00:00
<?php
namespace alveolata\html;
/**
* @param null|array $titles {null|list<string>}
* @param array $data {list<list<string>>}
*/
function table(
array $titles,
array $data
) : string
{
$html = '';
$html .= ("<table>\n");
if (! is_null($titles)) {
$html .= ("<thead>\n");
$html .= sprintf(
"<tr>%s</tr>\n",
implode(
'',
array_map(
function (string $title) : string {
return sprintf(
"<th>%s</th>",
$title
);
},
$titles
)
)
);
$html .= ("</thead>\n");
}
{
$html .= ("<tbody>\n");
foreach ($data as $line) {
$html .= sprintf(
"<tr>%s</tr>\n",
implode(
'',
array_map(
function (string $field) : string {
return sprintf(
"<td>%s</td>",
$field
);
},
$line
)
)
);
}
$html .= ("</tbody>\n");
}
$html .= ('</table>' . "\n");
return $html;
}
?>