{"id":969,"date":"2012-10-09T10:03:25","date_gmt":"2012-10-09T10:03:25","guid":{"rendered":"http:\/\/keithdevon.wpengine.com\/?p=969"},"modified":"2012-10-09T10:07:28","modified_gmt":"2012-10-09T10:07:28","slug":"the-php-ternary-operator","status":"publish","type":"post","link":"https:\/\/keithdevon.com\/the-php-ternary-operator\/","title":{"rendered":"The PHP ternary operator"},"content":{"rendered":"<p>In my quest to master PHP, I&#8217;m going to start investigating some of the bits I&#8217;m unfamiliar with, and blogging about them.<\/p>\n<p>This morning, I was reading through the excellent &#8220;Professional WordPress Plugin Development&#8221; by Brad Williams, Ozh Richards and Justin Tadlock (I&#8217;ve made a resolution to read a bit every couple of days). In the user settings section there is an example of a ternary operator.<\/p>\n<p>[code lang=&#8221;php&#8221;]$lang = $_POST[&#8216;boj_adminlang_lang&#8217;] == &#8216;es_ES&#8217; ? &#8216;es_ES&#8217; : &#8221;;[\/code]<\/p>\n<p>Frankly, I&#8217;m\u00a0embarrassed\u00a0that I&#8217;ve come across this syntax so many times without taking the time to understand it. Especially because it is so simple.<\/p>\n<p>The above code is short for:<\/p>\n<p>[code lang=&#8221;php&#8221;]if( $_POST[&#8216;boj_adminlang_lang&#8217;]\u00a0== &#8216;es_ES&#8217;\u00a0) {<br \/>\n$lang = &#8216;es_ES&#8217; ;<br \/>\n} else {<br \/>\n$lang = &#8221; ;<br \/>\n}[\/code]<\/p>\n<p>I&#8217;ve written so many statements using the longhand version. Time to level up!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my quest to master PHP, I&#8217;m going to start investigating some of the bits I&#8217;m unfamiliar with, and blogging about them. This morning, I was reading through the excellent &#8220;Professional WordPress Plugin Development&#8221; by Brad Williams, Ozh Richards and Justin Tadlock (I&#8217;ve made a resolution to read a bit every couple of days). In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[81,12],"tags":[82],"acf":[],"_links":{"self":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts\/969"}],"collection":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/comments?post=969"}],"version-history":[{"count":0,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts\/969\/revisions"}],"wp:attachment":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/media?parent=969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/categories?post=969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/tags?post=969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}