<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Knowledge Sharing &#187; Code</title>
	<atom:link href="http://blog.danigunawan.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.danigunawan.com</link>
	<description>"Say it... although a word..."</description>
	<lastBuildDate>Wed, 25 Jan 2012 00:14:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>IF Construct in One Line Using PHP</title>
		<link>http://blog.danigunawan.com/programming/if-construct-in-one-line-using-php/</link>
		<comments>http://blog.danigunawan.com/programming/if-construct-in-one-line-using-php/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 03:49:49 +0000</pubDate>
		<dc:creator>Dagu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Condition]]></category>
		<category><![CDATA[Construct]]></category>
		<category><![CDATA[If]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://blog.danigunawan.com/?p=582</guid>
		<description><![CDATA[The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C: if (expr) statement The general format of if construct is like shown below: if (expr1) { //  statement if expr [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The <em>if</em> construct is one of the most important   features of many languages, PHP included.  It allows for   conditional execution of code fragments.  PHP features an   <em>if</em> structure that is similar to that of C:</p>
<pre>if (expr)
   statement</pre>
<p>The general format of if construct is like shown below:</p>
<pre>if (expr1) {
   //  statement if expr 1 true
} else if (expr2) {
   // statement if expr 2 true
} else {
   // statement if expr 1 and 2 false
}</pre>
<p>You may find useful documentation about<em> </em><a title="if construct" href="http://us3.php.net/manual/en/control-structures.if.php" target="_blank"><em>if</em> construct</a>, <em><a title="else condition" href="http://us3.php.net/manual/en/control-structures.else.php" target="_blank">else</a> </em>and<em> <a title="else if" href="http://us3.php.net/manual/en/control-structures.elseif.php" target="_blank">else if</a> </em>in <a title="control structures" href="http://us3.php.net/manual/en/language.control-structures.php" target="_blank">php.net</a>.</p>
<p>But how if you only need two condition to produce a word or digit, and then save it into a variable or just echo it? You may write it like shown below:</p>
<pre>if ($status = '0')
   echo 'Draft';
else
   echo 'Published';</pre>
<p>In code example above, you need to write four lines. Compare with code shown below:</p>
<pre>echo $status == '0' ? 'Draft' : 'Published';</pre>
<p>The syntax is show below</p>
<pre>echo expr ? 'value if true' : 'value if false';</pre>
<p>You may change echo with variable assignment such as:</p>
<pre>$var = expr ? 'value if true' : 'value if false';</pre>
<p>Easy right? It cuts down four lines into one line only.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.danigunawan.com/programming/if-construct-in-one-line-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

