include - Optimize code php dynamic inclusions -



include - Optimize code php dynamic inclusions -

i have next code found on internet, i'm not php have way optimize next code:

<?php $pages = array( "home" => array( "title" => "title name page", "display" => "home.php", "description" => "description name page", ), "order" => array( "title" => "title name page", "display" => "order.php", "description" => "description name page", ), "contacto" => array( "title" => "title name page", "display" => "contacto.php", "description" => "description name page", ), 404 => array( "title" => "page not found", "display" => "404.php", "description" => "the page requested not found!", ) ); require('config.php'); if(isset($_get["page"])) { if (isset($pages[$_get["page"]])) { $page = $_get["page"]; $title = $pages[$page]["title"]; $display = $pages[$page]["display"]; $description = $pages[$page]["description"]; include('header.php'); include($display); include('footer.php'); } else { $page = 404; $display = $pages[$page]["display"]; $title = $pages[$page]["title"]; $description = $pages[$page]["description"]; include('header.php'); include($display); include('footer.php'); } } else { $page = "home"; $display = $pages[$page]["display"]; $title = $pages[$page]["title"]; $description = $pages[$page]["description"]; include('header.php'); include($display); include('footer.php'); } ?>

you believe there way optimize , includes many not utilize header / footer?

at to the lowest degree simplify if/else eliminate duplication

if(isset($_get["page"])) { if (isset($pages[$_get["page"]])) { $page = $_get["page"]; } else { $page = 404; } } else { $page = "home"; } $title = $pages[$page]["title"]; $display = $pages[$page]["display"]; $description = $pages[$page]["description"]; include('header.php'); include($display); include('footer.php');

php include

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -