I have custom array in php:
$tags = [
'portfolio',
'material',
'corporate'
];
How I can paste this array as javascript array in HTML element:
<div id="template" data-tags='["portfolio", "material", "corporate"]'></div>
I must do this task in php file and return to view.
I tired:
$result = "";
foreach ($tags as $tag) {
$result .= '"'.$tag.'",';
}
$result = '<div class="getTags" style="display:none;" data-tags=\'['.$result.']\'></div>';
return $result;
But here data tags type not an array, it's string. How I can solve this problem?