Can an array be specified in an ini file to be parsed using Zend_Config_Ini

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

Is there a way to specify a one dimensional array in a ini file.

so in my ini I would like to do

someproperty = [array of something]

I am using Zend_Config_Ini config adapter (I prefer ini for base configuration).

回答1:

someproperty[] = a someproperty[] = b someproperty[] = c someproperty[] = d someproperty[] = e 

see: http://us.php.net/manual/en/function.parse-ini-file.php#75983



回答2:

Although undocumented, this seems to work quite well too:

foo[bar] = 5 foo[baz] = 6 hello[world] = 7 


回答3:

You can use separators to make further sub-sections, and they are presented as either another level of objects ($config->some->a) or with $config->toArray(), they can be turned into a multi-level array.

Combining both the above techniques to make arrays, and the separators like so:

some.a[] = a some.a[] = b some.b[] = c 

will give the results you are looking for.

array('some' => array('a' => array(0 => 'a',                                    1 => 'b'),                       'b' => array(0 => 'c')                      )); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!