I\'m running a PHP script and continue to receive errors like:
Notice: Undefined variable: my_variable_name in C:\\wamp\\www\\mypath\\index.php on line 10
I didn't want to disable notice because it's helpful, but wanted to avoid too much typing.
My solution was this function:
function ifexists($varname)
{
return(isset($$varname)?$varname:null);
}
So if I want to reference to $name and echo if exists, I simply write:
=ifexists('name')?>
For array elements:
function ifexistsidx($var,$index)
{
return(isset($var[$index])?$var[$index]:null);
}
In page if I want to refer to $_REQUEST['name']:
=ifexistsidx($_REQUEST,'name')?>