/** * Assigns a new tag to use that will get replaced, all array keys * will get converted to lower case! * * @param array $tags * @param bool $overwrite If a tag already exists, should it be overwriten or appended? * @param bool $allowHtml should HTML be allowed in the tag value? * @param bool $prepend Prepend content to the tag, instead of append * @return object */ public function assign(array $tags, $overwrite = true, $allowHtml = false, $prepend = false) { if ($this->caseSensitive === false) { zula_array_key_case($tags, CASE_LOWER); } foreach ($tags as $tag => $val) { if ($allowHtml == false) { $val = $this->cleanTagValue($val); } unset($tags[$tag]); $tags[$this->cleanTag($tag)] = $val; } if (empty($this->assignedTags)) { $this->assignedTags = $tags; } else { if ($overwrite == false) { /** * Allows tags that have been assigned more than once to be * appended onto the end, instead of overwriting the old tag */ foreach ($tags as $key => $val) { if (isset($this->assignedTags[$key])) { if (is_array($val)) { if ($prepend) { $this->assignedTags[$key] = zula_merge_recursive($val, $this->assignedTags[$key]); } else { $this->assignedTags[$key] = zula_merge_recursive($this->assignedTags[$key], $val); } } else { if ($prepend) { $this->assignedTags[$key] = $val . $this->assignedTags[$key]; } else { $this->assignedTags[$key] .= $val; } } } else { $this->assignedTags[$key] = $val; } } } else { $this->assignedTags = zula_merge_recursive($this->assignedTags, $tags); } } return $this; }
/** * Changes the case of an arrays keys recursively * * @oaram array $arr * @param int $case * @return bool */ function zula_array_key_case(array &$arr, $case = CASE_LOWER) { $arr = array_change_key_case($arr, $case); foreach ($arr as &$val) { if (is_array($val)) { zula_array_key_case($val, $case); } } return true; }