Matpatnik Posted January 25, 2007 Share Posted January 25, 2007 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 More sharing options...
Obi1-Cannabis Posted January 25, 2007 Share Posted January 25, 2007 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 More sharing options...
MrAdam Posted January 25, 2007 Share Posted January 25, 2007 haha. i don't even think that's right - it will be looking for braces to know when the if ends, unless you only have one statement and therefore do not need braces. Link to comment Share on other sites More sharing options...
pulpfiction Posted January 25, 2007 Share Posted January 25, 2007 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 More sharing options...
justsomeguy Posted January 25, 2007 Share Posted January 25, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now