Non riesco a trovare alcun esempio, nei libri o sul web, descrivendo come si inizializza correttamente un array associativo solo per nome (con valori vuoti) - a meno che, ovviamente, questo è il modo correttoInizializzazione di una matrice associativa con nomi di chiave ma valori vuoti
E 'appena sente come se c'è un altro modo più efficiente per fare questo (?):
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.
Qualunque consigli, suggerimenti, o la direzione sarebbe apprezzato. Grazie.
Ehi, non è importante, ma che hai scritto 'dbname' -> '' in cui avrebbe dovuto essere 'dbname' => ' '- Non ho abbastanza reputazione per apportare la modifica. – Martha