Which is better to use ifelse or if else? Are they the same?
-
☆ A M B ☆
- 24,524 Posts
No, they’re not the same, but I can’t make heads nor tails of exactly what the difference is...
In PHP, you can also write ’else if’ (in two words) and the behavior would be identical to the one of ’elseif’ (in a single word). The syntactic meaning is slightly different (if you’re familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.
If you’re coming from another language that does not have the "elseif" construct (e.g. C++), it’s important to recognise that "else if" is a nested language construct and "elseif" is a linear language construct; they may be compared in performance to a recursive loop as opposed to an iterative loop...This test should show that "elseif" executes in roughly two-thirds the time of "else if".
I think it’s a case of a difference that really doesn’t make much of a difference.