php键顺序初始化,php – 使用键名称但是空值初始化关联数组

我找不到任何例子,在书中或在网络上,描述如何正确地初始化一个关联数组的名称只有(用空值) – 除非,当然,这是正确的方式(?)

它只是觉得,有另一种更有效的方式来做到这一点:

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'] = '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.

任何建议,建议或方向将不胜感激。谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值