Nested arrays in ini file

前端 未结 4 701
小鲜肉
小鲜肉 2021-01-11 13:36

I am trying to have a nested array structure inside an ini settings file. The structure i have is:

stuct1[123][a] = \"1\"
stuct1[123][b] = \"2\"
stuct1[123][         


        
4条回答
  •  渐次进展
    2021-01-11 14:42

    You can create a minimum of three levels. Maybe more, but I don't know how to do so.

    '.print_r($ini_array,true).'
    '); ?>

    parse_ini_file.ini

    ; 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"
    second_section[one]="1 associated"
    second_section[two]="2 associated"
    second_section[]="1 unassociated"
    second_section[]="2 unassociated"
    
    [third_section]
    phpversion[] = "5.0"
    phpversion[] = "5.1"
    phpversion[] = "5.2"
    phpversion[] = "5.3"
    

    Output

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

提交回复
热议问题