Setting default value: $var = (isset($var)) ? $_POST['var']
Posted: Mon Sep 10, 2007 5:12 pm
I am using a form script and want to check for the value of $val, it can be set either from a config file or from a hidden field in a form...
1# First I want to check the value doesn't exist or has been set in the config file
2# if not then check if it has been set in the form
3# then if not set a default value for $var
So to cut down on the if, elseif's I tried to do it as follows:
unfortunately if the value $var is set the isset($var) in the above line doesn't seem to read that it has a value, nor does POST and it just sets it to 'DEFAULT_VALUE'
anyone any idea?
Thanks
1# First I want to check the value doesn't exist or has been set in the config file
2# if not then check if it has been set in the form
3# then if not set a default value for $var
So to cut down on the if, elseif's I tried to do it as follows:
Code: Select all
$var = (isset($var)) ? $_POST['var'] : 'DEFAULT_VALUE';anyone any idea?
Thanks