Code:
/******************************************************************************
* This functions sets the value of a variable.
*
* It may be called with either a varname and a value as two strings or an
* an associative array with the key being the varname and the value being
* the new variable value.
*
* The function inserts the new value of the variable into the $varkeys and
* $varvals hashes. It is not necessary for a variable to exist in these hashes
* before calling this function.
*
* An optional third parameter allows the value for each varname to be appended
* to the existing variable instead of replacing it. The default is to replace.
* This feature was introduced after the 7.2d release.
*
*
* usage: set_var(string $varname, [string $value = ""], [boolean $append = false])
* or
* usage: set_var(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false])
*
* @param $varname either a string containing a varname or a hash of varname/value pairs.
* @param $value if $varname is a string this contains the new value for the variable otherwise this parameter is ignored
* @param $append if true, the value is appended to the variable's existing value
* @access public
* @return void
*/
function set_var($varname, $value = "", $append = false) {
if (!is_array($varname)) {
if (!empty($varname)) {
if ($this->debug & 1) {
printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value));
}
$this->varkeys[$varname] = "/".$this->varname($varname)."/";
if ($append && isset($this->varvals[$varname])) {
$this->varvals[$varname] .= $value;
} else {
$this->varvals[$varname] = $value;
}
}
} else {
reset($varname);
while (list($k, $v) = each($varname)) {
if (!empty($k)) {
if ($this->debug & 1) {
printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v));
}
$this->varkeys[$k] = "/".$this->varname($k)."/";
if ($append && isset($this->varvals[$k])) {
$this->varvals[$k] .= $v;
} else {
$this->varvals[$k] = $v;
}
}
}
}
}