public static cssStyleFromArray ( array $style ) : string | ||
$style | array | the CSS style array. The array keys are the CSS property names, and the array values are the corresponding CSS property values. |
return | string | the CSS style string. If the CSS style is empty, a null will be returned. |
public static function cssStyleFromArray(array $style)
{
$result = '';
foreach ($style as $name => $value) {
$result .= "{$name}: {$value}; ";
}
// return null if empty to avoid rendering the "style" attribute
return $result === '' ? null : rtrim($result);
}