Skip to content

Instantly share code, notes, and snippets.

@kitsunet
Forked from mortendk/theme.inc
Last active August 29, 2015 14:00
Show Gist options
  • Save kitsunet/11193630 to your computer and use it in GitHub Desktop.
Save kitsunet/11193630 to your computer and use it in GitHub Desktop.
function mergeAttributes($array) {
$mergedAttributes = array();
foreach(func_get_args() as $argument) {
foreach($argument as $key => $value) {
if (!isset($mergedAttributes[$key]) {
$mergedAttributes[$key] = array();
}
if (is_array($value)) {
foreach($value as $innerValue) {
$mergedAttributes[$key][] = $innerValue;
}
} else {
$mergedAttributes[$key][] = $value;
}
}
}
return $mergedAttributes;
}
$variables['attributes']['class'] = 'test-attribute-merge-1';
$variables['content_attributes']['class'] ='test-content_attributes-merge-2';
$variables['attributes']['role'] = 'attributes-role';
$variables['content_attributes']['role'] = 'content_attributes-role';
$variables['title_attributes']['role'] = 'title-attributes-role';
$variables['item_attributes']['0']['role'] = 'item-attributes-role';
//wtf why u not merge
$variables['attributes_test'] = mergeAttributes($variables['attributes'], $variables['content_attributes'], $variables['title_attributes']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment