[英]Update xml elemnt inside function. How to pass elemnt inside function
showOrUpdate($day->Date, $_POST['Date'])
and function: 和功能:
function showOrUpdate($element, $value)
{
if (isset($value) && !empty($value))
{
$element = $value;
}
return $element;
}
but problem is that $element
is not passed as element but is passed as readable value and is then for example 2013-08-22 and not $day->Date
. 但问题是
$element
没有作为元素传递,而是作为可读值传递,然后是例如2013-08-22,而不是$day->Date
。
but I want to pass it in function and inside function update value and later save it. 但是我想在函数和函数内部更新值中传递它,然后保存它。
like: 喜欢:
$day->Date = $value;
Is this possible? 这可能吗?
What you are referring to is commonly know as pass by reference. 您所指的通常称为按引用传递。 When defining a function use the '&' sign for variables that you want to pass by reference.
定义函数时,对要通过引用传递的变量使用“&”号。
function showOrUpdate(&$element, $value) {
if (isset($value) && !empty($value))
$element = $value;
}
This would update the original value of $element. 这将更新$ element的原始值。 Also, in this situation you don't need to use a return statement as the variable has already been modified within the function itself.
同样,在这种情况下,您不需要使用return语句,因为变量已在函数本身中进行了修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.