Home » PHP » Use a custom PHP function [library]

Use a custom PHP function [library]

code reuse

By using existing code repeatedly, the development efficiency is improved and the cost is reduced

Include () and require () functions [frequently asked questions]

Require () imports a file during preprocessing, such as pasting the file to the place where the function is used,.


include () is almost equivalent to require (), and differs from the.

when it is included in script execution; when the process fails, include () generates a warning, and require () causes a fatal error

include_once () and require_once () functions

two functions during the execution of the script and run the specified file. And including include () and require () statement is similar, the only difference is that if the code in the file has been included, will not only include again, including one. These two functions should be used during the execution of the script in the same a file may be included more than once the case, you want to make sure that it is only a function to avoid including redefined.
variable re assignment problem





Require ' config.php' require; / / use statement contains and execute the config.php file
If ($condition) / / using a include statement in process control
Include ' file.txt' include; / / use statement contains and execute the file.txt file
Else / condition includes the following documents
Include (' other.php'); / / include statement contains and execute the other.php file
Require (' somefile.txt' require); / / use statement contains and execute the somefile.txt file
example:


Error_reporting (0);
Require "function.inc.php"";
If ($a== "a") include "demo.txt"";
Else include "demo2.html"";
(one);
(two);
Three (
function.inc.php); Jiangzi:


Function, one () {
Echo "1111111
"";
}
Function, two () {
Echo "222222
"";
}
Function, three () {
Echo "333333
"";
}


The HTML there is Jiangzi:


bbbbbbbbbbbbbbbbbbbbbb


> Jiangzi

bbbbbbbbbbbbbbbbbbbbbb

1111111

222222

333333





P.s.

This article is written content is less, so the following xuxutaotao write something else ~


at the end of last year ended.Net assignment and the school race really is just passable, just passable, the expected difference distance away, but also reluctantly said in the past, the day before yesterday and today to relax before finishing the PHP function of the knowledge point and a half days, mainly because of a month away, forget too hard, again, is the first times to learn when the light is not solid, it is not enough to see the video, is expected to put the anonymous functions and closures done before 7 night Linux, tomorrow there is a day of their own time is really too happy tomorrow is linux+ ~ ~ should state compression.


think back to the past year, it is full to burst the whole state, suddenly remember, at night there are bestcoder, adjust the state, ~~go~go~go~


When

30, the day is on the nine floor to go out, he was not good, see the teacher talking at the door and other teachers, he is approximately equal to the step a little rub out, do not want to have the feeling of T^T, we actually back to sleep also boast to me (*, *) B a ninth what delighted me ah, but not this year, next year, is to find a job! People ah T^T, now learn too few, not to mention the game do not put, obviously felt the lack of time.


!


Latest