|
Posted by Jerry Stuckle on 10/06/90 11:44
Oli Filth wrote:
> Jerry Stuckle said the following on 08/04/2006 16:11:
>
>> Tim Martin wrote:
>>
>>>
>>> function get_post_var_with_default($name, $default = 'default value')
>>> {
>>> if (isset($_POST[$name]))
>>> {
>>> return $_POST[$name];
>>> }
>>> else
>>> {
>>> return $default;
>>> }
>>> }
>>>
>>> then later
>>>
>>> $var = get_post_var_with_default('postvar');
>>>
>>> Am I missing something here?
>>>
> > And you'd need another one for $_SESSION, and another one for $_GET.....
>
>>
>> And what if you want to do it for a non-super global - i.e. an array
>> member?
>>
>> With macros you need only one, i.e.
>>
>> $var = GET_WITH_DEFAULT($_POST['myvar']), 'default value');
>> $var2 = GET_WITH_DEFAULT_VALUE($myarray['test'], 'default_value);
>>
>
>
> function getWithDefault(&$array, $key, $default = NULL)
> {
> return (isset($array[$key])) ? $array[$key] : $default;
> }
>
>
And if $array is empty you get a warning.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|