You are here: Re: Is there a shortcut i'm missing? « PHP Programming Language « IT news, forums, messages
Re: Is there a shortcut i'm missing?

Posted by Christoph Burschka on 03/26/07 18:20

Jerry Stuckle wrote:
> Lo'oris wrote:
>> $name=$_GET['name'];
>> if (!$name)
>> $name="value";
>>
>> i can't figure out how to shorten this thing. Is there some kind of
>> operator i don't know about?
>>
>
> $name = isset($_GET['name']) ? $_GET['name'] : null;
>
> You should always test with isset() to see if a value passed to your
> page is set or not. Otherwise you will get a notice if you have them
> enabled.
>

If setting multiple variables from $_GET, you can also try this:

$parameters=array('name'=>"value",'example'=>"value1",'another'=>"value2");
foreach ($parameters as $parameter=>$value)
{
$$parameter=$_GET[$parameter]?$_GET['parameter:$value;
}

--
cb

 

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

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