我无法在书籍或网页上找到任何示例,描述如何正确初始化仅按名称(具有空值的关联数组) - 当然,除非这样方法得当使用键名称初始化关联数组但是空值
它只是感觉好像还有另一种更有效的方式来做到这一点(?):
的config.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.
的index.php
require config.php
config::$database['dbdriver'] = 'mysql';
config::$database['dbhost'] = 'localhost';
config::$database['dbname'] = 'test_database';
config::$database['dbuser'] = 'testing';
config::$database['dbpass'] = '[email protected]$$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.
任何建议,意见或建议,将不胜感激。谢谢。
嘿,并不重要,但你写 'DBNAME' - > '',它应该已经 'DBNAME'=>' ' - 我没有足够的声望来进行编辑。 – Martha