使用键名但值为空值初始化关联数组
2022-08-30 09:40:49
我无法在书籍或网络上找到任何示例来描述如何仅按名称(使用空值)正确初始化关联数组 - 当然,除非这是正确的方法(?)
它只是感觉好像有另一种更有效的方法可以做到这一点:
配置.php
class config {
public static $database = array (
'dbdriver' => '',
'dbhost' => '',
'dbname' => '',
'dbuser' => '',
'dbpass' => ''
);
}
// Is this the right way to initialize an Associative Array with blank values?
// I know it works fine, but it just seems ... longer than necessary.
索引.php
require config.php
config::$database['dbdriver'] = 'mysql';
config::$database['dbhost'] = 'localhost';
config::$database['dbname'] = 'test_database';
config::$database['dbuser'] = 'testing';
config::$database['dbpass'] = 'P@$$w0rd';
// This code is irrelevant, only to show that the above array NEEDS to have Key
// names, but Values that will be filled in by a user via a form, or whatever.
任何建议,意见或指示将不胜感激。谢谢。