我無法在書籍或網頁上找到任何示例,描述如何正確初始化僅按名稱(具有空值的關聯數組) - 當然,除非這樣方法得當使用鍵名稱初始化關聯數組但是空值
它只是感覺好像還有另一種更有效的方式來做到這一點(?):
的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