Mastering the Use of PHP Conditionals


No set of control structures is more pervasive in programming than if, elseif and else. With a few exceptions, you’ll use at least one per function or method that you write. There’s just no way around it. But conditionals (that’s what we call these control structures) fit in the “easy to learn, hard to master” category. In fact, they’re so easy to use that you can develop some bad habits around them. (This is also a problem with loops.) This can lead to code that’s complex and hard to read or even test.
That said, it’s possible to develop good programming habits with conditionals. This is what this article will try to help you with. We’ll go over some programming techniques that can help make conditionals more manageable.
First, let’s take a look at how PHP evaluates conditionals. This is so often misunderstood when using conditionals. But knowing how PHP evaluates them lets you remove and/or combine conditionals. This, in turn, makes your code simpler.
Evaluation order of a conditional
The first thing that you should always keep in mind is the order that conditionals get evaluated. Most programming languages evaluate conditionals
Source: https://managewp.org/articles/13822/mastering-the-use-of-php-conditionals




source https://williechiu40.wordpress.com/2016/11/11/mastering-the-use-of-php-conditionals/