Q: Using too many if blocks is good ? what are possible alternatives? I have been designing a shopping website lately in PHP. Now in Checkout page i have to check many times if the user is logged in. i.e If the user is logged in hide the Signin div and show the Shipping div.
<section class="panels <?php if(!isset($_SESSION['username'])) echo"unactivepanel"; else echo"activepanel";?>" id="Sign In">
        <div class="wrapper1" >
            <ul>
            <li><input type="email" placeholder="Enter your email address" required/></li>
            <li class="inf">(will only be used for sending you order information.)</li>
            <fieldset><legend class="orb"> OR</legend>
            <li><input type="button" value="Sign In to booksmore" class="sb si llb" /></li></fieldset>
            <fieldset><legend class="orb"> OR</legend>
            <li>Sign In using any of following service:</li>
            <li>
                <div class="box1 fc">Facebook</div>
                <div class="box1 tw">Twitter</div>
                <div class="box1 gg">Google</div>
                <div class="box1 oi">Open Id</div>
            </li></fieldset>

            </ul>
        </div>
    </section>
    <section class="panels <?php if(!isset($_SESSION['username'])) echo"unactivepanel"; else echo"activepanel";?>unactivepanel" id="Shipping"></section>
    <section class="panels unactivepanel" id="Confirm"></section>

What i have studied is using too many if block slows down the executions speed, So am I right using too many if blocks ? if I am not coding it right(what i feel right now) then what may be the possible alternatives to if blocks ? (I was thinking of using switch block.)

A: If you are using same if else at every place you can easily refactor like.
<?php 
if(!isset($_SESSION['username'])) 
 $class = "unactivepanel"; 
else 
 $class = "activepanel";
?>

now simply do echo $class wherever you need it,like
 <section class="panels <?php echo $class;?>unactivepanel" id="Shipping"></section>


A: Tarun is right. Also a switch case will only ever help you when you have multiple possible code blocks that all rely on the value of a single variable. In your case a swtich block would be pointless.
