本文整理汇总了PHP中Variable::setVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP Variable::setVariable方法的具体用法?PHP Variable::setVariable怎么用?PHP Variable::setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable::setVariable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setData
$answer = null;
}
$this->data[strtoupper($variablename)] = $answer;
return $this->data[strtoupper($variablename)];
}
return null;
}
function setData($variablename, $answer, $clean = 1)
{
/* variable in memory */
if (isset($this->variables[strtoupper($variablename)])) {
$variable = $this->variables[strtoupper($variablename)];
} else {
$variable = new Variable();
if (!$variable->setVariable($variablename)) {
$variable = null;
}
}
/* we have variable */
if ($variable != null) {
$variable->setDirty($clean);
/* check for EMPTY */
if (strtoupper($answer) == VARIABLE_VALUE_EMPTY || is_array($answer) && sizeof($answer) == 0 || !is_array($answer) && trim($answer) == "") {
$answer = null;
}
if ($variable->setAnswer($this->primkey, $answer)) {
/* update in-memory */
$this->variables[strtoupper($variablename)] = $variable;
$this->data[strtoupper($variablename)] = $answer;
//echo 'set ' . $variablename . ' to ' . $answer;
/* update state memory if array update
* (this does not happen in variable.php via $engine->setAnswer()
* in order to avoid an infinite loop)
*/
global $engine;
$var = $engine->getVariableDescriptive($variablename);
if ($var->isArray() && contains($variablename, "[")) {
//echo 'set ' . $variablename . ' to ' . $answer;
$arr = $this->getData(getBasicName($variablename));
$index = str_replace("]", "", substr($variablename, strrpos($variablename, "[") + 1));
// update array
$arr[$index] = $answer;
// flatten array
$arr = flatten($arr);
// flatten array
$this->data[strtoupper(getBasicName($variablename))] = $arr;
//print_r($arr);
} else {
if (($var->getAnswerType() == ANSWER_TYPE_SETOFENUMERATED || $var->getAnswerType() == ANSWER_TYPE_MULTIDROPDOWN) && !contains($variablename, "_")) {
$options = $var->getOptions();
$values = explode(SEPARATOR_SETOFENUMERATED, $answer);
foreach ($options as $o) {
$code = $o["code"];
if (isset($this->data[strtoupper($variablename . "_" . $code . "_")])) {
if (!inArray($code, $values)) {
$this->data[strtoupper($variablename . "_" . $code . "_")] = null;
}
} else {
if (inArray($code, $values)) {
$this->data[strtoupper($variablename . "_" . $code . "_")] = $code;
}
}