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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:03:27+00:00 2026-06-04T06:03:27+00:00

$foo=1; function someFunction(){ if($foo==0){ //——-Will test, won’t execute bar(); }elseif($foo==1){ //–Will test, and execute

  • 0
$foo=1;

function someFunction(){
  if($foo==0){ //-------Will test, won't execute
    bar();
  }elseif($foo==1){ //--Will test, and execute
    baz();
  }elseif($foo==2){ //--Doesn't test
    qux();
  }elseif($foo==3){ //--Doesn't test
    quux();
  }else{ //-------------Doesn't test
    death();
  } //------------------The program will skip down to here.
}

Let’s say that baz() changes the value of $foo and it is different every time. I want my code to keep testing the elseif/else statements after the first one and run those if they are true.

I don’t want to run the whole function again, (i.e. I don’t care if $foo = 0 or 1). I’m looking for something like “continue;”. Anyways please let me know if this is possible. Thanks. 🙂

EDIT** My code is actually way more complicated than this. I was just putting some code down for the sake of theory. All I want is the script to keep testing where it usually wouldn’t.

  • 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-06-04T06:03:28+00:00Added an answer on June 4, 2026 at 6:03 am

    If I’m understanding correctly, you want to do each consecutive elseif, regardless of whether previous if/elseifs matched, but you also want some code to run if none of the if/elseifs match. In this case, you can set a flag $matched to be set to true if one of them matches and use ifs instead.

    <?php
    $foo=1;
    function someFunction(){
      $matched = false;
      if($foo==0){
        bar();
        $matched = true;
      }
      if($foo==1){ //--This elseif will get executed, and after it's executed,
        baz();
        $matched = true;
      }
      if($foo==2){
        qux();
        $matched = true;
      }
      if($foo==3){
        quux();
        $matched = true;
      }
      if(!$matched){ /* Only run if nothing matched */
        death();
      }
    }
    

    If you also want to be able to skip to the end, use goto (but see this first):

    <?php
    $foo=1;
    function someFunction(){
      $matched = false;
      if($foo==0){
        bar();
        $matched = true;
        goto end: // Skip to end
      }
      if($foo==1){ //--This elseif will get executed, and after it's executed,
        baz();
        $matched = true;
      }
      if($foo==2){
        qux();
        $matched = true;
      }
      if($foo==3){
        quux();
        $matched = true;
      }
      if(!$matched){ /* Only run if nothing matched */
        death();
      }
      end:
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class Foo(): function bar(): pass function foobar(): pass Rather than executing each
Consider some function foo : def foo(input) input * 2 end How to get
I know that if I am inside some function foo() which is called somewhere
How can I include foo() function of foo.c in this small program (sorry for
function runAgain() { window.setTimeout(foo, 100); } function foo() { //Do somthing runAgain(); } I
I have a function foo that accepts a Boolean function def foo( f:(_)=>Boolean )
I have a ColdFusion function foo which takes three args, and the second two
Say I have the following function: foo <- function(x, y = min(m)) { m
Given the following javascript: function foo(selectControl) { ... } and the following html: <select
Suppose you have the following function foo . When I'm running a for loop,

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.