Home > Backend Development > PHP Tutorial > javascript - PHP一个页面根据传的不同值显示不同的内容

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

WBOY
Release: 2016-06-06 20:33:34
Original
1659 people have browsed it

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

回复内容:

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

stackoverflow 上看到的:

<code><?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");
</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template