INI file to multidimensional array in PHP

前端 未结 5 1733
花落未央
花落未央 2021-01-18 08:51

I have the next INI file:

a.b.c = 1
a.b.d.e = 2

I am parsing this file using parse_ini_file. And it returns:

array(
    \'a         


        
5条回答
  •  旧巷少年郎
    2021-01-18 09:51

    This is how I see it:

     &$value) {
                if (is_array($value)) {
                    self::fix_ini_multi($value);
                }
                if (strpos($key, '.') !== FALSE) {
                    $key_arr = explode('.', $key);
                    $last_key = array_pop($key_arr);
                    $cur_elem = &$ini_arr;
                    foreach ($key_arr AS $key_step) {
                        if (!isset($cur_elem[$key_step])) {
                            $cur_elem[$key_step] = array();
                        }
                        $cur_elem = &$cur_elem[$key_step];
                    }
                    $cur_elem[$last_key] = $value;
                    unset($ini_arr[$key]);
                }
            }
        }
    
    }
    
    
    var_dump(ParseIniMulti::parse('test.ini'));
    

提交回复
热议问题