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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:00+00:00 2026-05-23T11:55:00+00:00

I have a php file in which i am using a really very long

  • 0

I have a php file in which i am using a really very long switch case. I want to split the cases in different files (keep logically connected cases in 1 file).

EDIT: Sorry everyone it was my code that was causing problem. The switch case was working as expected.

file -> a.php

echo "<br>RES = ".test(1);

function test($value) {
    switch($value) {
        case (1 || 2):
                include("b.php");
                            **return $temp;**
                break;

        default: echo "error";
                return 3;
                break;
    }
}

file -> b.php

switch($value) {

    case 1: echo "value is 1";
                    **$temp = 1;**
            return 1;
            break;

    case 2: echo "value is 2";
                    **$temp = 2;**
                    return 2;
                    break;
}

How do i get proper result? if the switch case of b.php is in a.php file then everything works fine.Any idea/suggestion on how to do this?

If i add $temp (bold lines) then it works…

Thanks for help in advance.

Regards

  • 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-23T11:55:01+00:00Added an answer on May 23, 2026 at 11:55 am

    Updated response to updated question:
    modify “a.php” and prefix a return infront of the “b.php” include:

    return include("b.php");
    

    http://www.php.net/manual/en/function.include.php

    Handling Returns: It is possible to
    execute a return() statement inside an
    included file in order to terminate
    processing in that file and return to
    the script which called it. Also, it’s
    possible to return values from
    included files. You can take the value
    of the include call as you would a
    normal function. This is not, however,
    possible when including remote files
    unless the output of the remote file
    has valid PHP start and end tags (as
    with any local file). You can declare
    the needed variables within those tags
    and they will be introduced at
    whichever point the file was included.


    simple include()’s within your case/break sections?

    switch($var)
    {
     case 1:
       include('case_1.php');
       break;
     case 2:
       include('case_2.php');
       break;
     default:
       include('case_default.php');
      break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file which I will be using as exclusively as an
I have an XML file which I need to parse using PHP and send
I am using php and mysql. I have a Database config file (db-config.php) which
I have an index.php file which has to process many different file types. How
I have a PHP file which will return something like <div id=title>Add Us On
i have one php file which process adding of record in Database fro array.
I have a php file which has a require_once Statement (?) this file is
I have a php file that contains a form (which contains 2 input boxes
I have a PHP app that creates a CSV file which is forced to
I have this code which will include template.php file from inside each of these

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.