/********************************************************************************/
/* TITLE : Fastest way to implode an associative array with keys
/* DESCRIPTION : To Get the details fastest way to implode an associative array with keys
/* CREATED BY : Jemiris Selvi S
/* CREATED ON : 11-July-2017
/* MODIFIED BY : Jemiris Selvi S
/* MODIFIED ON : 11-july-2017
/********************************************************************************/
<?php
$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);
?>
<div class="image-box" <?= $dataAttributes; ?> >
<img src="http://example.com/images/best-of.jpg" alt="">
</div>
----------------------------------
/* TITLE : Fastest way to implode an associative array with keys
/* DESCRIPTION : To Get the details fastest way to implode an associative array with keys
/* CREATED BY : Jemiris Selvi S
/* CREATED ON : 11-July-2017
/* MODIFIED BY : Jemiris Selvi S
/* MODIFIED ON : 11-july-2017
/********************************************************************************/
<?php
$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);
?>
<div class="image-box" <?= $dataAttributes; ?> >
<img src="http://example.com/images/best-of.jpg" alt="">
</div>
----------------------------------
Comments
Post a Comment