Home > Backend Development > PHP Tutorial > PHP reads array from file as configuration file

PHP reads array from file as configuration file

WBOY
Release: 2016-08-08 09:21:19
Original
1109 people have browsed it
You may have seen many open source products. Most of their configuration files are stored in a separate file, and this file only stores an array. In fact, a little PHP trick is used here, that is, the file can be Include it and assign it to a variable. This variable will have the entire configuration array. Let me give you an example:
config.php
--------------- -----------

return array(
                                                                                                       ' ' c' => 3,
);
?>
getconfig.php
-------------------------- ---

$config = require('config.php');
print_r($config);
?>
Everyone try it and you will find $ The config variable stores the array in config.php. This is how PHP can use the file as a return function.
The above introduces PHP to read the array in the file as the configuration file, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template