将默认主页添加到以下代码中

How can you add a default page to this code? For example: visiting domain.com in my case will display the included "home" page, but how can you define it in the pages array? I don't want to have to type in domain.com/index.php?page=home just because the name "home" is specified in the array. I would like domain.com www.domain.com and domain.com/index.php?page=home all to be the same if that makes since. Thank you.

    <?php

$pages = array('home', 'about', 'services', 'faq');
$titles = array('Home', 'About us', 'Services', 'FAQ');

$index = array_search($_POST['p'], $pages);
if ($index !== false) {
   $page_content = 'includes/' . $pages[$index] . '.php';
   $title_name = $titles[$index];
} else {
   print 'Page not found';
}

?>

Currently you're keying off of $_POST['p']. If no value is specified for $_POST['p'] then you can just use a default. Try something like this:

$pages = array('home', 'about', 'services', 'faq');
$titles = array('Home', 'About us', 'Services', 'FAQ');

$page = 'home';
if (isset($_POST['p'])) {
   $page = $_POST['p'];
}

$index = array_search($page, $pages);
if ($index !== false) {
   $page_content = 'includes/' . $pages[$index] . '.php';
   $title_name = $titles[$index];
} else {
   print 'Page not found';
}

Here we've slightly abstracted the $_POST['p'] value behind a variable. This allowed us to define a default value for that variable and only override that value if $_POST['p'] is provided. The the search is conducted on that variable.

I would like to propose a cleaner approach than @David's answer:

$pages = array(
  'home'  => 'Home', 
  'about' => 'About us',
  'services' => 'Services',
  'faq' => 'FAQ'
);

$page = 'home';
if (isset($_POST['p']) && array_key_exists($_POST['p'], $pages)) {
   $page = $_POST['p'];
}
$page_content = 'includes/' . $page . '.php';
$title_name = $pages[$page];

Notice that OP wants to have a "default" page (which is home.php) being displayed, therefore "Page not found" case is not required.

thank you for all the replies. I have a switch statement that works as intended, but it doesn't offer a no page found. I basically wanted this in case someone tried to type the url directly like domain.com/index.php?page=abc or they misspelled the page name, so it would display a page not found I setup.I found this code a few days ago here and I thought it would help cleanup the long switch statement. So the page not found is something that I would like. @david...I quickly tested your code, but if I attempt a page that's know is in the includes folder it still displays just the default "home" page.