我想知道我是否在 if 语句中包含一个 .php 文件(或任何文件),如下所示:
<?php
$a = 1;
if($a == 0) include 'somefile.php';
?>
既然那将是错误的,那么 somefile.php 会完全由浏览器加载还是不会被加载,从而导致客户端必须下载的数据量较少?
我想知道我是否在 if 语句中包含一个 .php 文件(或任何文件),如下所示:
<?php
$a = 1;
if($a == 0) include 'somefile.php';
?>
既然那将是错误的,那么 somefile.php 会完全由浏览器加载还是不会被加载,从而导致客户端必须下载的数据量较少?
First of all its not loaded by the browser but by php on the server. And no it will not be loaded when the condition is false.
As Jasper pointed out: Whatever you include in a php script has very little to do with how much is sent to the browser. Php interprets the code and creates html that is sent to the user's browser. You could have a 1000000 lines of codes file that just echoes "1" and the browser would get only a couple of kb of data. Even if 100 megs of php where processed.
It is pretty easy to test. Create a dummy.php file containing:
<?php echo 'hello world';
To test this:
if(true){ include("dummy.php");} //will echo hello world
if(false){ include("dummy.php");} //will not echo hello world
To test it try it with passing true and the false to the if and you will see two different results.
Then include this file in an if statemant and see if it echoes hello world.