有没有办法将一个get变量添加到php include中

Mat*_*iby 1 php

我想这样做......是否有可能

<?php include("includes/sidebar.php?show_hide_tab=true"); ?>
Run Code Online (Sandbox Code Playgroud)

因为有些页面在侧栏中不需要一些逻辑

Mar*_*iek 6

就这样做吧

<?php
    $show_hide_tab = true;

    include('includes/sidebar.php');
?>
Run Code Online (Sandbox Code Playgroud)

$show_hide_tab变量的范围将落入包含脚本.

  • 为清楚起见,这里的[php manual](http://us2.php.net/manual/en/function.include.php)必须说:"当包含文件时,它包含的代码继承了变量范围发生包含的行.**从那一点开始,调用文件中该行可用的任何变量都将在被调用文件**中可用. (3认同)