0
i have a question that what is the need of elseif statement if our work can be done by using number of if. same output will be produced then what is the basic purpose of elseif?
10 Respostas
+ 1
because an elseif statement isn't check if the if statement is True like
if (1 == 1)
{
echo 1;
}
elseif (2 == 2)
{
echo 2;
}
return 1 and
if (1 == 1)
{
echo 1;
}
if (2 == 2)
{
echo 2;
}
return 12
0
you need elseif statement if you have more than two condition in your code.
0
thanks francis.. i got it
0
elseif is used when u have to check for more than one independant condition
0
U can also use switch instead of elseif. It is much more efficient
0
sumitabha...can u explain ur point with an eg. plz
0
I can give you examples, but u wont be satisfied, because switch compares the variable with every individual value that it can hold, and the code will be extremely tedious to write if the variable has to be checked within a large range. In that case elseif serves the purpose much more efficiently and cleanly.
0
Eg.
if(marks<30)
echo fail;
else if(marks>=30 && marks<50)
echo pass;
else if (marks>50)
echo good;
0
Switch only works more efficiently if the variable is compared with a small no. of values, otherwise in all cases elseif is better
0
multiple if's are costlier than elseif.