PHP, like most programming or scripting language allows for comparison operations bu using if/else. It’s a staple of any good language yet at the same time you can end up writing a lot of code in order to accomplish something very simple. Take for example this simple comparison:
$action = 'default';
$action = $_POST['action'];
All we’re doing here is assigning one value to $action if the form variable action isn’t empty, and different variable if it is. This took up eight lines of code (OK, so you could argue that you could lower that by moving braces around but the code gets ugly fast). How can we clean this up? Enter ternary operators!
What’s a ternary operator you ask? In a nutshell, a ternary operator takes three elements and combines them into one. The basic syntax is (expression 1) ? (expression 2) : (expression 3); which means do expression 2 if expression 1 is true, otherwise do expression 3. It’s just an if/else condition rewritten in one simple line. Taking our previous example, we could consolidate it to this:
$action = (empty($_POST['action'])) ? 'default':$_POST['action'];
Voila! The exact same results in one easy to understand line. I am a huge fan of this shortcut and it comes in very handy when you have basic if/else conditions to check.
I can’t listen to the radio anymore. Free radio that is. I’ve had satellite radio for over a year now and it’s the only thing, aside from mix CDs, that I listen to in my car anymore. It’s obvious how the state of modern music has degenerated over the last decade or so. Now groups like Nickelback and Hinder, which sound damn near identical to me, plague the free airwaves.Â Hate is a pretty strong word so I’ll just say that I can’t bring myself to listen to Nickelback, and their sound-alike counterpart Hinder. They’re horrible. I don’t know where to begin other than they’re the musical equivalent of a root canal. Even on the satellite radio shuffle channel I can instantly detect either of these talentless artists and when I check to see what’s playing, it’s inevitably one of them. Not to pick on these two bands but they need to do everyone a favor and pack up and go. There are arguable plenty of other talentless, fabricated musicians and bands out there that should join them. It’s rare to see an artist last for more than one album any more. Just look at the iTunes charts over the past few years and see what I mean. Oh and before you ask where I get off, I’ll just add that I worked with a Grammy winning musician for several years and leave it at that.
We are in a reverse renaissance.
You’re probably asking yourself, “What are leader dots?”. Whenever I design forms, I’ve always felt that the text labels should either be left justified and lined up next to the form fields they correspond to, or directly above them. It’s just one of those things. Even when presenting data that is suited to form or tabular data where the name of a field and the contents are both to be displayed, I can’t accept seeing the fields another way, particularly right justified so they but up against the data, or data entry fields. Continue reading Leader Dots with CSS
Welcome to Catch My Fame. For now, CMF is a place where I’ll share my 11+ years of IT experience and 8+ years of web development and design experience with you. I consider myself stuck somewhere between web developer and designer. I have worked on big celebrity web sites, small home grown mom and pop sites, and everything in between and have both developer skills (PHP, Perl, ASP, MySQL) and designer skills. I’m a designoper. I’ll share my insight, frustrations, and solutions to the wonderful work of web sites. So sit back, read, share, and learn.