i want want to parse html attribute with function. in my fnction implode do not work correctly and could not convert array to simple string.
for example my array Result is:
Array
(
[0] => id='myLabel'
[1] => class='myClass'
[2] => style='width:100%;'
)
after imploding that i get this Result:
Array
(
[0] => 0='id='myLabel' class='myClass' style='width:100%;''
)
Result must be:
Array
(
[0] => "id='myLabel' class='myClass' style='width:100%;'"
)
My function :
public function setAttribute( $attributs ){
$html = [];
foreach ( (array)$attributs as $key => $value) {
$html[] = $key .'='. "'".$value."'";
}
return implode( $html, ' ');
}
$keyholdsarray indexvalue. That's y in your array preceding with00andweird quotesafter implode.setAttribute.