i'm in need of a php function whose first argument will check that the variable exist or not outside of the function, if variable exist then echo it's value and if the variable doesn't exist then echo a default value for the variable given in second argument of the function. and in last remove(delete) both the variable passed to the function just after echoing their values.
simply :
function if_exists ($argument, $default)
{
// if $argument exist then echo it's value and then remove $argument variable.
// if the $argument doesn't exist then echo it's $default value and then remove $default variable.
}
i will use it like this :
$any_variable if_exists ($any_variable, 'this variable is not defined');
this code is not doing the perfect job for me :
function if_exist(&$argument, $default = '')
{
if (isset ($argument))
{
echo $argument;
}
else
{
echo $default;
unset ($default);
}
}
thanks.
if_exists()outputs something and additional change the given arguments.