Reputation: 20916
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
.
but I want to pass it in function and inside function update value and later save it.
like:
$day->Date = $value;
Is this possible?
Upvotes: 1
Views: 45
Reputation: 325
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. Also, in this situation you don't need to use a return statement as the variable has already been modified within the function itself.
Upvotes: 1