php - split switch cases in different files -


i have php file in using long switch case. want split cases in different files (keep logically connected cases in 1 file).

edit: sorry code causing problem. switch case working 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 1";                     **$temp = 1;**             return 1;             break;      case 2: echo "value 2";                     **$temp = 2;**                     return 2;                     break; } 

how proper result? if switch case of b.php in a.php file works fine.any idea/suggestion on how this?

if add $temp (bold lines) works...

thanks in advance.

regards

updated response updated question: modify "a.php" , prefix return infront of "b.php" include:

return include("b.php"); 

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

handling returns: possible execute return() statement inside included file in order terminate processing in file , return script called it. also, it's possible return values included files. can take value of include call normal function. not, however, possible when including remote files unless output of remote file has valid php start , end tags (as local file). can declare needed variables within tags , introduced @ whichever point file included.


simple include()'s within 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; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -