You are here: Re: Macros in php « PHP Programming Language « IT news, forums, messages
Re: Macros in php

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация