Home > Backend Development > PHP Tutorial > 配置管理 - PHP中像这样的配置需求该如何实现?

配置管理 - PHP中像这样的配置需求该如何实现?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:07:05
Original
1047 people have browsed it

最近做的一个东西需要自己设置几个配置文件.
配置文件本身就是php文件,用数组做配置.
然后因为其中可能包含一些对逻辑的配置,比如

<code class="php">$config = [
    "a" => 666,
    "b" => 777,
    "x" => "" //可以填 ">","=","</code>
Copy after login
Copy after login

然后在程序里以这个配置来决定一些运算结果该怎么处理.
除了用

<code class="php">switch($config['x']){
    case ">":
        if(a>b){
        }
        break;
    case "</code>
Copy after login
Copy after login

这种笨办法之外,还有什么优雅的实现方式吗?
或者能否推荐相关教程/源码/文章.非常感谢!

回复内容:

最近做的一个东西需要自己设置几个配置文件.
配置文件本身就是php文件,用数组做配置.
然后因为其中可能包含一些对逻辑的配置,比如

<code class="php">$config = [
    "a" => 666,
    "b" => 777,
    "x" => "" //可以填 ">","=","</code>
Copy after login
Copy after login

然后在程序里以这个配置来决定一些运算结果该怎么处理.
除了用

<code class="php">switch($config['x']){
    case ">":
        if(a>b){
        }
        break;
    case "</code>
Copy after login
Copy after login

这种笨办法之外,还有什么优雅的实现方式吗?
或者能否推荐相关教程/源码/文章.非常感谢!

你那个不叫配置,而是参数数组。通常是这样的:

<code>$config = array(
    'useableOp' => array('>', '=', '</code>
Copy after login
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template