What is faster: many ifs, or else if in PHP?


An else if is a better option.

Below is a sample code for multiple if statements −

if(condition_A){
   //perform some action
}
if(condition_B){
   //perform some action
}

Below is a sample code for else if statement −

if(condition_A){
   //perform some action
}
else if(condition_B){
   //perform some action
}

When else if statements are used, if a condition is satisfied, the checking stops there and the operations associated with the condition are executed. This way, the operations and conditions get over quickly.

Updated on: 06-Apr-2020

581 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements