Jump to content

elseif or else if?


Matpatnik

Recommended Posts

I have a question that start bugging me, maybe it's a stupid question but hey! I'll survive :) What is the difference between "elseif" and "else if"?To me it does the same thing but I'm sure there is a difference between both of them. In few book of php they write "else if" and some other book (and in w3schools) they write "elseif"!Is one is newer or deprecated?What is the best one to stick with it?

Link to comment
Share on other sites

I have a question that start bugging me, maybe it's a stupid question but hey! I'll survive :) What is the difference between "elseif" and "else if"?To me it does the same thing but I'm sure there is a difference between both of them. In few book of php they write "else if" and some other book (and in w3schools) they write "elseif"!Is one is newer or deprecated?What is the best one to stick with it?
the difference is that 'elseif' is faster because the parser considers that you're still inside the same 'if' block, only with another condition, while using 'else if' the parser will have to think if that 'if' is still inside the other one or if it's a new one inside the 'else'. Or so i was told... :)
Link to comment
Share on other sites

One thing to point out is, there can be multiple ELSEIF in a IF block but there can be only one ELSE. IF (expression) statements ELSEIF (expression) statements ELSEIF (expression) statements . .ENDIFBut if you start a IF the you need to end it.IF (expression) statementsELSE IF (expression) Statements END IFEND IF

Link to comment
Share on other sites

Practically there is no difference. These are functionally equivalent, and any performance differences will be too small to measure.

if (){}else if (){}else if (){}else{}if (){}elseif (){}elseif (){}else{}

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.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...