Coders Opinion

Using the short if statement

Introduction

user

Robert-Jan de Dreu

Hey, I’m Robert-Jan de Dreu. A freelance software engineer, developing software since 2009. While using PHP and Javascript I build well structured and tested software.

About Me Hire Me
Featured

PHP Development

Using the short if statement

Posted by Robert-Jan de Dreu on .

I’m always lost when I need to find the shorthand version of the if statement in php. That is why I write again a small note for myself so I can find it again.

$value = 'sunny';
$weather = ($value == 'sunny')
    ? "It is a sunny day"
    : "Stay in bed its raining";

echo $weather;

There are multiple implementations for the short tag but this is the one I use the most. Maybe I document others too when I feel like it.

user

Robert-Jan de Dreu

http://codersopinion.com

Hey, I’m Robert-Jan de Dreu. A freelance software engineer, developing software since 2009. While using PHP and Javascript I build well structured and tested software.