Last active
November 16, 2017 04:40
-
-
Save r17x/e3a4f00249e0a7e00227a78ae34f9e43 to your computer and use it in GitHub Desktop.
arrayToHtmlAttributes.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @author ri7nz <[email protected]> | |
*/ | |
function toAttributes($arr){ | |
$arr = array_map( | |
function($value, $key){ | |
return $key.'="'.$value.'"'; | |
}, | |
array_values($arr), | |
array_keys($arr) | |
); | |
return implode(' ', $arr); | |
} | |
$attr = array( | |
'id' => 'input1', | |
'class' => 'form-control', | |
'name' => 'input1' | |
); | |
$attr = toAttributes($attr); | |
echo "<input type='text' ${attr} />"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment