Re: Simple coding question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Octavian Rasnita wrote:
Hi all,

Please tell me which is the shortest method for writing the following code:

$var = $_GET['var'] || 'value';

I want the program to put the value "value" in the variable $var if the
array element 'var' is not defined or in case it is 0 and I would like to
avoid using that long style with if (..) {...} else {...}...

Thank you.

Teddy
Like the others said, use the ? : method:

$var = (isset($_GET['var']) && $_GET['var']) ? $_GET['var'] : 'value';

--
Daniel Schierbeck

Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/register&r=6584

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux