I\'m looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use \'<
This is my solution for example for an div data-attributes:
$attributes = array(
'data-href' => 'http://example.com',
'data-width' => '300',
'data-height' => '250',
'data-type' => 'cover',
);
$dataAttributes = array_map(function($value, $key) {
return $key.'="'.$value.'"';
}, array_values($attributes), array_keys($attributes));
$dataAttributes = implode(' ', $dataAttributes);
?>
>