Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:04:46+00:00 2026-05-26T12:04:46+00:00

I was wondering if complicated if/else structures in my PHP code could be a

  • 0

I was wondering if complicated if/else structures in my PHP code could be a bad design decision. Does having a lot of if statements make PHP run slow, site load slower etc?

This is the code:
(I’ve no idea how wordpress handles is_page etc.)

<?php

if (is_page()) {
//
    if (is_page(122)) {
    //subscribe page
    echo "subscribe page";

    }

    elseif (is_page(1263)) {
    //photography course
    echo "photography course page";

    }

    elseif (is_page(array(210,184,128))) {
    //210 copyright policy, 184 privacy policy, 128 contact
    echo "this is either copyright policy, privacy or contact page!";
    //nothing happens here, we don't need social buttons on these pages.
    }

    elseif (is_page(array(379,71,7,45,124,8,105,175,9,125,110))) {
    //379 photo galleries, 71 car photos, 7 conceptual, 45 event photos, 124 fashion, 8 landscape, 105 misc, 175 journalism, 9 portrait, 125 street photography, 110 travel
    echo "gallery pages and albums";

    }

    else {
    //any other page
    echo "any other page";

    }
//
}

elseif (is_single()) {
//
    if (in_category(array(147,196,35))) {
    //147 car photography, 196 car wallpapers, 35 photo stories
    echo "photo posts";

    }
    else {
    //any other post
    echo "any other post";

    }
//
}

elseif (is_archive()) {
//
    //any category
    echo "this is archive template"

}
//
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:04:47+00:00Added an answer on May 26, 2026 at 12:04 pm

    Nope. In fact, it’ll actually speed it up in most cases (because it’s allowed to skip over blocks of code).

    The only time large numbers of if statements will slow it down is if the condition you’re checking requires processing. An example would be something like:

    while (true)
    {
        if (count($some_array) == 0) { break; }
        /* some other code */
    }
    

    Ever iteration through the loop checks if count($some_array) == 0. That means that every pass, PHP has to go and manually count the number of items in $some_array because it may have changed. This also applies to the stop condition in a for loop. This is because a for loop can always be rewritten as a while loop:

    for ([INITIALIZER_ACTION]; [CONDITION]; [POST_ITERATION_ACTION]) { [CODE]; }
    

    is the same as…

    [INITIALIZER_ACTION];
    while ([CONDITION]) { [CODE]; [POST_ITERATION_ACTION]; }
    

     

    If you’re considering merging a bunch of if statements into one: don’t, you won’t get any benefits. PHP does short circuiting which means that if it reaches a point where it knows what the outcome will be, it’ll skip the rest.

    For example, consider $a = 5; if ($a > 0 || $b > 100 || $c > 200) {}.
    Once PHP sees that the $a > 0 condition is satisfied, the whole statement resolved to true (because of the usage of OR values) and doesn’t bother to check $b > 100 or $c > 200.

    So to answer your question: unless you have an ungodly number of conditionals that each require complicated calculations or have side effects, you can usually consider the quantity of them to be inconsequential.
    However, as others have noted, having too many if statements can reduce code readability. In many cases, if you can remove a conditional without it affecting the behavior of the code, then you didn’t need it to begin with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if you guys could help with a complicated query. I have
I was wondering if anyone knows how could I make my own "Webpage screenshot
I've been working with a lot of semi-complicated XSD's lately and am wondering: What
I have kind of a complicated case and am wondering how this would work
I'm just wondering if this is even possible; how to do non-complicated scripting within
So it's not a complicated matter at all, but was wondering how the Stackoverflow
Wondering if there is a way I could trigger an event, so that any
Just wondering if its worth it to make a monolithic loop function or just
I'm wondering how to write this query, it's a little complicated... This is an
I'm working on some complicated form at the moment. Just wondering, is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.