You are here: Re: please explain or refer: $string = isset($xyz) ? $xyz : "something else"; « PHP Programming Language « IT news, forums, messages
Re: please explain or refer: $string = isset($xyz) ? $xyz : "something else";

Posted by Jason F. on 05/10/05 22:54

juglesh wrote:
> "$string = isset($xyz) ? $xyz : "something else";"
>
>
> Hello, someone gave code like this in another thread. I understand (by
>
> inference) what it does, but have not found any documentation on this
> type of syntax.

That's the ternary operator, which you'll find in a lot of languages
besides just PHP.

The above example is exactly equivalent to:

if (isset($xyz)) {
$string = $xyz;
} else {
$string = "something else";
}

In the interest of *easily readable code* I would recommend that you try
*NOT* to use the ternary much just to appear clever. Sure, it's more
compact, but it takes a couple extra seconds to figure out what's going
on VS an if/else.

 

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

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