Get list of cases in switch statement
$pages = array('about'=> 'About Us', 'services' => 'Services');
if (array_key_exists($page, $pages)) {
$title_name = $pages[$page];
$page_content = "includes/$page.php";
include('inner.php');
}
For your footer you can just iterate over the list of pages. To add a new page, just add it to the array and create the corresponding file.
But to answer your question: No, you can't analyze code-statements during runtime.
Nope, it's not possible using switch
- but you could store those informations in an array:
$page_list = array(
'about' => array(
'title' => 'About Us',
'content' => 'includes/about-us.php',
),
'services' => array(
'title' => 'Services',
'content' => 'includes/services.php',
),
);
if(isset($page_list[$page])) {
$page_info = $page_list[$page];
$title_name = $page_info['title'];
$page_content = $page_info['content'];
include("inner.php");
} else {
// 404 - file not found
}
// create links
foreach($page_list as $link_name => $page_ent) {
echo "<a href=\"/{$link_name}/\">{$page_ent['title']}</a><br />"
}
// output
// <a href="/about/">About Us</a><br />
// <a href="/services/">Services</a><br />