- implode: documentation ( source)
- array_filter: documentation ( source)
- array_walk: documentation ( source)
- sprintf: documentation ( source)
<?php
class A
{
public function __construct()
{
echo $this->formatColumnsWithValues(['key' => 'value', 'foo' => 'bar', 'empty' => '']);
}
private function formatColumnsWithValues(array $kRow): string
{
$kRow = array_filter($kRow);
array_walk($kRow, fn (&$v, $k) => $v = sprintf("%s: %s\n", $k, $v));
return implode("</p><p>", $kRow);
}
}
$a = new A();