Configuration Management-How does a configuration requirement like this in PHP be implemented?

Source: Internet
Author: User
One of the most recent things to do is to set up several configuration files yourself.
The configuration file itself is a PHP file, configured with an array.
Then because it might contain some configuration of logic, such as

$config = [    "a" => 666,    "b" => 777,    "x" => "" //可以填 ">","<",">=","<="等等]

Then in the program with this configuration to determine how some of the results of the operation to deal with.
In addition to using

switch($config['x']){    case ">":        if(a>b){        }        break;    case "<":        if(a
  
   < code="">

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

Reply content:

One of the most recent things to do is to set up several configuration files yourself.
The configuration file itself is a PHP file, configured with an array.
Then because it might contain some configuration of logic, such as

$config = [    "a" => 666,    "b" => 777,    "x" => "" //可以填 ">","<",">=","<="等等]

Then in the program with this configuration to determine how some of the results of the operation to deal with.
In addition to using

switch($config['x']){    case ">":        if(a>b){        }        break;    case "<":        if(a
  
    < code="">

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

You don't call it a configuration, it's an array of parameters. This is usually the case:

  $config = Array (' useableop ' = = ' Array (' > ', ' < ', ' = = ', ' >= ', ' <= '), function do ($param 1, $param 2, $op) {if (! In_array ($op, $config [' Useableop '])) {throw new \    Exception (' invalid operator ');    } $param 1 = (int) $param 1;    $param 2 = (int) $param 2;    Eval ("\ $result = {$param 1} {$op} {$param 2}"); return $result;  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.