Skip to content

Instantly share code, notes, and snippets.

@SimonJThompson
Created May 16, 2014 09:37
Show Gist options
  • Save SimonJThompson/db47d457a65d034c441c to your computer and use it in GitHub Desktop.
Save SimonJThompson/db47d457a65d034c441c to your computer and use it in GitHub Desktop.
Function to convert an associative array to a string of HTML element attributes.
<?php
/*
Takes an associative array and converts them to HTML element attributes
*/
function array_to_attr($attrs) {
$r="";
if(is_array($attrs)) {
foreach($attrs as $attr => $val) {
$r.=$attr.="=\"".$val."\" ";
}
}
return $r;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment