<?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>My Galagzee! &#187; ternary</title>
	<atom:link href="http://my.galagzee.com/tag/ternary/feed/" rel="self" type="application/rss+xml" />
	<link>http://my.galagzee.com</link>
	<description>Tech in a Galagzee, Not So Far Away.</description>
	<lastBuildDate>Fri, 20 Jan 2012 18:46:41 +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>Ternary beauty</title>
		<link>http://my.galagzee.com/2010/02/08/ternary-beauty/</link>
		<comments>http://my.galagzee.com/2010/02/08/ternary-beauty/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 23:06:33 +0000</pubDate>
		<dc:creator>Ville Walveranta</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ternary]]></category>

		<guid isPermaLink="false">http://my.galagzee.com/?p=391</guid>
		<description><![CDATA[I love the ternary operator. It can often simplify a much more complex conditional into few characters. In PHP (and other c-like languages) it&#8217;s possible to do all sorts of things with the ternary. The following are examples from PHP. &#8230; <a href="http://my.galagzee.com/2010/02/08/ternary-beauty/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I love the ternary operator. It can often simplify a much more complex conditional into few characters.  In PHP (and other c-like languages) it&#8217;s possible to do all sorts of things with the ternary. The following are examples from PHP.</p>
<p>If $b is true, print &#8220;true&#8221;, otherwise print &#8220;false&#8221;. Echo doesn&#8217;t work here.</p>
<pre class="brush: php; title: ; notranslate">
$b ? print &quot;true&quot; : print &quot;false&quot;;
</pre>
<p>Here&#8217;s something I learned today: it&#8217;s possible to assign a complex variable to an &#8220;internal&#8221; shorthand, and then in turn use the shorthand for the final assignment (based on the comparison). This way it&#8217;s not necessary to repeat the complex variable in the assignment section which makes the ternary much shorter and thus cleaner.</p>
<p>So instead of this:</p>
<pre class="brush: php; title: ; notranslate">
$a = ($myObject-&gt;anotherObject-&gt;arr['somekey'] &gt; 7 ? 7 : $myObject-&gt;anotherObject-&gt;arr['somekey']);
</pre>
<p>You can do this:</p>
<pre class="brush: php; title: ; notranslate">
$a = (($b = $myObject-&gt;arr['somekey']) &gt; 7 ? 7 : $b);
</pre>
<p>Awesome!! <img src='http://my.galagzee.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://my.galagzee.com/2010/02/08/ternary-beauty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

