file - Generate PHP switch based on folder content -


let have folder containing 3 files; file1.php, file2.php, file3.php. in same folder, have index.php, want generate switch cases each file.

$files = array(); $folder = opendir(realpath(dirname(__file__))); while ($file = readdir($folder)) {      if (strpos($file, '.php') !== false && $file !== 'index.php') {          array_push($files, $file);       } }  $switch = $_get['component']; switch($switch) {     foreach ($files $file) {         case str_replace('.php', '', $file):        include_once($file);                break;     }    } 

what cases in end:

$switch = $_get['component']; switch($switch) {         case file1:     include_once('file1.php');              break;         case file2:     include_once('file2.php');              break;         case file3:     include_once('file3.php');              break; } 

um... seems convoluted me.

if( in_array($_get['component'].".php",glob("*.php")) && $_get['component'] != "index")     include_once($_get['component'].".php"); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -