Reduce code with the ternary operatorWhen writing applications, it's important to find ways to reduce code. More code equals more development, more maintenance, and more headaches. One quick way to help reduce code is to use "ternary" (also often called "tertiary") syntax for simple Consider this PHP example:
if ($var == true) {
$go = 1;
}
else {
$go = 0;
}
This is an extremely basic
As you can see, we start out by setting the The One thing to be aware of is you must include an "else" result (the portion after the colon). Sometimes your For example, this would not work:
Hope this quick tip helps save you some lines of code.
Comments/Mentions
|
Editor Picks
Email NewsletterSubscribe to the digest newsletter to receive posts by email: Recent Comments
Advertisements
|