首页 > PHP一个页面根据传的不同值显示不同的内容

PHP一个页面根据传的不同值显示不同的内容

请各位大神告诉我一种简单的方法。
我自己想的是用get传值,根据传的不同的值显示不同内容。但是要用好多if语句我才能实现。那样太麻烦了。请各位大神给菜鸟小弟支个招,万分感谢。


stackoverflow 上看到的:

<?php
include("header.php"); 
$page = isset($_GET['page']) ? trim(strtolower($_GET['page'])) : "home";
$allowedPages = array(
    'home'     => './home.php',
    'about'    => './about.php',
    'services' => './services.php',
    'gallery'  => './gallery.php',
    'photos'   => './photos.php',
    'events'   => './events.php',
    'contact'  => './contact.php'
);
include(isset($allowedPages[$page]) ? $allowedPages[$page] : $allowedPages["home"]);
include("footer.php");

switch.要不if吧。无所谓。不要过早的优化代码。得不偿失

【热门文章】
【热门文章】