Original link: https://my.oschina.net/banbo/blog/299370
PHP has an include, as its name implies, is used to include files. The corresponding require, as well as two with once. I wonder if you have noticed the return value of the include. Typically, contains a successful return of 1, including failure to return false. However, if the included file is returned with return, then the value is the value of returns. Like what:
1.php
<?php
$ret = include ' 2.php ';
Echo $ret; Output Wakaka
?>
2.php
<?php return
' Wakaka ';
? >
You can see from the 1.php output that the return value of the include is the ' Wakaka ' in 2.php.
What is the use of this feature? I use it to conveniently use PHP files for configuration. For example, a configuration file can be written like this:
config.php
<?php return
Array ('
db ' =>array ('
host ' => ' localhost ',
' user ' => ' root ',
' password ' => ' Wakaka ',
' name ' => ' Test ',
' encoding ' => ' UTF8 '
)
);
? >
When loading, only need $conf = include ' config.php '; This is how the thinkphp configuration file is returned.