简体   繁体   中英

Define constant through looping

I try to define constant value through looping, but it got error:

Notice: Use of undefined constant XXXXX - assumed 'XXXXX' in XX on line XX

This is the code:

$q = "SELECT `Key`, `Value` FROM appconfig";
//I skip the line to read from database
while($fetch = mysqli_fetch_array($r)) {
    define("'" . $fetch["Key"] . "'", $fetch["Value"]);
    //I try to echo $fetch["Key"] and $fetch["Value"] and it returns value
}

Something wrong with the code? I tried to define it manually and it works.

不要使用引号,你不需要它们:

define($fetch["Key"], $fetch["Value"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM