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

  • SEARCH
  • Home
  • 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 542k
  • Answers 542k
  • 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 Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 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

This should be a simple question, but I haven't been able to find a
This should a quick question for some easy rep. I'm doing some PHP Website
I know this should be simple and I should know it but it's eluding
This should hopefully be a simple one. I would like to add an extension
This should be a really really simple thing, but for some reason it is
This should be straight forward for a guru. I don't have any code really
This should be fine seeing as the CLR hasn't actually changed? The boxes running
This should be easy for many of you, but for me it's just another
This should be easy, but I'm not sure how to best go about it.
It seems like this should be straightforward but I'm boggling. I've got my listview

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.