-8

次のように、if ステートメント内に .php ファイル (またはその他のファイル) を含めるかどうかを知りたかったのです。

<?php
    $a = 1;
    if($a == 0) include 'somefile.php';
?>

それは誤りなので、ブラウザによって somefile.php がまったくロードされるのでしょうか、それともロードされないので、クライアントがダウンロードする必要があるデータの量が少なくなるのでしょうか?

4

1 に答える 1

2

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.

于 2012-10-30T13:56:45.173 に答える