Include and require in php are accidentally seen today.
In PHP, the include () and require () functions are the same, but there are some differences in usage. include () is a conditional inclusion function, while require () it is an unconditional include function. For example, in the following example, if the variable $ somgthing is true, it will contain the file somefile:
If ($ something ){
Include ("somefile ");
}
However, no matter what value $ something takes, the following code will include the file somefile into the file:
If ($ something ){
Require ("somefile ");
}
The following interesting example fully demonstrates the differences between the two functions.
$ I = 1;
While ($ I <3 ){
Require ("somefile. $ I ");
$ I ++;
}
In this code, each loop contains the same file. Obviously, this is not the original intention of the programmer. from the code, we can see that this code will include different files in each loop. To complete this function, you must turn to the include () function ():
$ I = 1;
While ($ I <3 ){
Include ("somefile. $ I ");
$ I ++;
}