【问题标题】:parse_ini_file like php.iniparse_ini_file 像 php.ini
【发布时间】:2012-03-31 13:01:22
【问题描述】:

我注意到如果我喜欢

thing = abc
thing = def
thing = xyz

我在数组中只有一个条目。

但是 php.ini 有多个“扩展”声明,我假设它们都作为一个数组。

parse_ini_file 可以做同样的事情吗? INI_SCANNER_RAW 选项似乎没有改变这一点。

【问题讨论】:

标签: php arrays ini


【解决方案1】:

如果您想要一个thing 数组,您需要将您的声明更改为thing[]。来自文档:

; This is a sample configuration file
; Comments start with ';', as in php.ini

[first_section]
one = 1
five = 5
animal = BIRD

[second_section]
path = "/usr/local/bin"
URL = "http://www.example.com/~username"

[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"

会导致

Array
(
    [one] => 1
    [five] => 5
    [animal] => Dodo bird
    [path] => /usr/local/bin
    [URL] => http://www.example.com/~username
    [phpversion] => Array
        (
            [0] => 5.0
            [1] => 5.1
            [2] => 5.2
            [3] => 5.3
        )

)
Array
(
    [first_section] => Array
        (
            [one] => 1
            [five] => 5
            [animal] => Dodo bird
        )

    [second_section] => Array
        (
            [path] => /usr/local/bin
            [URL] => http://www.example.com/~username
        )

    [third_section] => Array
        (
            [phpversion] => Array
                (
                    [0] => 5.0
                    [1] => 5.1
                    [2] => 5.2
                    [3] => 5.3
                )

        )

)

【讨论】:

    猜你喜欢
    • 2013-05-10
    • 2011-08-09
    • 2012-06-17
    • 2015-05-06
    • 1970-01-01
    • 2012-12-11
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多