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 968121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:25:43+00:00 2026-05-16T02:25:43+00:00

This should be a simple question. I have a simple if/else statement: <?php //

  • 0

This should be a simple question. I have a simple if/else statement:

    <?php
    // TOP PICTURE DEFINITIONS
    if ( is_page('english') ) {
        $toppic = 'page1.png';
    }
    if ( is_page('aboutus') ) {
        $toppic = 'page1.png';
    }
    if ( is_page('newspaper') ) {
        $toppic = 'page1.png';
    }
    else {
        $toppic = 'page1.png';
    }
?>

Is there a difference from ^^^ to this:

<?php
    // TOP PICTURE DEFINITIONS
    if ( is_page('english') ) {
        $toppic = 'page1.png';
    }
    elseif ( is_page('aboutus') ) {
        $toppic = 'page1.png';
    }
    elseif ( is_page('newspaper') ) {
        $toppic = 'page1.png';
    }
    else {
        $toppic = 'page1.png';
    }
?>

I should mention that this is going into WordPress. And until now, I’ve used the first part (no elseif, just a series of ‘ifs’), and it works. I was just curious to know what the difference was.

Thanks!
Amit

  • 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-16T02:25:43+00:00Added an answer on May 16, 2026 at 2:25 am

    Yes. If a condition in an if/else control is satisfied, the rest of the checks will be omitted. else if is just a nested if inside an else!

    if ( is_page('english') ) { // if true, other statements are skipped
        $toppic = 'page1.png';
    }
    elseif ( is_page('aboutus') ) {
        $toppic = 'page1.png';
    }
    elseif ( is_page('newspaper') ) {
        $toppic = 'page1.png';
    }
    else {
        $toppic = 'page1.png';
    }
    

    But in a series of ifs, all of them will be tested.

    if ( is_page('english') ) {
        $toppic = 'page1.png';
    }
    if ( is_page('aboutus') ) { // will be tested no matter what the outcome
                                // of the previous if statement was
        $toppic = 'page1.png';
    }
    if ( is_page('newspaper') ) { // the same here
        $toppic = 'page1.png';
    }
    else {
        $toppic = 'page1.png';
    }
    

    So, if you’re checking a property such as parity of a number, it’s either odd or even, why do you want to bother checking other conditions if one is satisfied. It’s a waste of resources. Therefore, the following code is much better

    if(number_is_odd) {
    }
    else { // if it's not odd, it's even for sure
    }
    

    than

    if(number_is_odd) {
    }
    
    if(!number_is_odd) {
    }
    

    Because the former checks the condition once whilst the latter does it twice. The same thing goes for conditions with more than two states.

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

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It might have been exactly due to the fact that… May 16, 2026 at 11:37 am
  • Editorial Team
    Editorial Team added an answer If you want to contribute to a project that uses… May 16, 2026 at 11:37 am
  • Editorial Team
    Editorial Team added an answer For FireFox, you can use this: https://developer.mozilla.org/en/DOM:window.getComputedStyle For IE, you… May 16, 2026 at 11:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a simple if-else statement--if true, I'd like it to echo this content:
i have a LAPP (linux, apache, postgresql and php) environment, but the question is
I have a simple problem, yet i am unable to solve this. Either my
I have a WSDL generated by WCF and now this WSDL should be used
In a simple if-else case (where the denominator of a fraction will need to
I have the need to express simple conditionals as program input. The input must
I have a simple little code fragment that is frustrating me: HashSet<long> groupUIDs =
With a CMS (PHP/MySQL) that's getting bigger and bigger and its code harder to
I have an Address object defined simply as follows: public class Address { public
We have a class Event (it's actually named differently, but I'm just making abstraction):

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.