No way to remove an already included file.
The code is interpreted on the server side by the PHP module, which also generates the web page to be viewed on the client side.
This means that each time the user refreshes the page or opens the page it sends a requirement to the server and the server interprets the code on the server side (server-side).
What I mean by this is that there would be no need to remove include since when a new requirement is made everything is done from the beginning, so if we have a condition:
if($var == true)
{
include "file1.php";
} else {
include "file2.php";
}
In the first request if the variable $var
is equal to true
the file file1.php
will be included, but if another request is made and the variable $var
for falsa
the file file2.php
will be included and the file file1.php
it will not exist, this because, as I said, when a requirement is made it starts again.
I made a little code to exemplify that, test for yourself.
Testb.php
<?php
echo "Hello from A";
Testa.php
<?php
echo "Hello from A";
Test.php
<?php
$var = $_GET['n'];
switch($var)
{
case 1:
{
include "testA.php";
break;
}
case 2:
{
include "testB.php";
break;
}
}
You will find that by changing the value of n no link (test.php?n=1 or test.php?n=2) the existing previous file will not be included.
Hi Gustavo, I replied, but I would like to know the purpose of this, why so I can perhaps suggest you an alternative to do something similar :)
– Guilherme Nascimento
It would not be better to create a function that returns an array with all includes and then just invoke them?
– rray
@rray Great strategy +1 is worth a response
– Guilherme Nascimento
@Guilhermenascimento variables receive the information of a form, and depending on the choice of a select for example, I include a file with a block of text (will form a full text joining these blocks)... Do you understand that? So sometimes I have to swap these blocks, because a later choice (a select on another page) includes another file instead of the one that would be included if the previous choice did not affect the later one...
– gustavox
@rray and how would I do it? Can you give an example?
– gustavox