简体   繁体   中英

PHP nested if/else statement

I want to know may I put "if else" inside of different "if else" in PHP? Thank you.

For example:
if(...){
......
}
elseif(...){
      elseif(...){
            .....
           }
}

Is it wrong?

If your question is about syntax no you can't. Cause once you are inside of the elseif block php expects you to start with if. If it's about coding always try to avoid if elseif. Most of the cases switch case does the trick. In other case return early pattern does the trick(this is my favorite and cleanest solution IMO).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM