开发者

how marge each value from the same array onto each key

I have this array and I can't figure out how to dissect it and get it to built onto itself.

I have compiled my array to what I think might be the easiest to keep track of:

Array
(
    [domain.com] => Array
        (
            [dev] => Array
                (
                    [path] => /var/www/config/
                    [ini] => Array
                        (
                            [0] => db
                            [1] => common
                        )

                )

            [theme] => Array
                (
                    [path] => /var/ww/themes/
                    [ini] => theme
                )

        )

)

My whole thing is that I want to make a helper class to parse ini files. So I have through a couple of methods been able to build my array like above.

My end goal is have something like this parse_ini_file($ini[$domain][$nick][path] . $ini[$domain][$nick][ini] . ".ini", true)

where $nick is either 'dev' or 'theme' its just a way for me to distinguish paths and ini that belong together.

I have tried to do a foreach loop through each key value pair but I'm stuck on the fact that one o开发者_运维问答f my values holds an array.

foreach (self::$ini[$domain] as $k => $v) {
    //if (self::$ini[$domina][$nick]['path'][$k] === self::$ini[$domain][$nick]['ini'][$k])
        foreach (self::$ini[$domain][$k] as $i => $l) {

            foreach ($l as $m => $n)
                //if (!is_array($i)) {

                   // (strlen($i) - 1 === '/' ? $i : $i . '/');
                    echo $n;
                    //self::$built = parse_ini_file($i . $j, true);
                //}
            }
}

It may seem like a mess, but i didn't bother with making meaningful variable names until I am able to make a solid code block. But In my attempt I have done a foreach loop through the $domain array to extract each $nick from there I thought doing another foreach to then break it down to get the path and ini key => values to then built the parse ini file function. But like I said, one of my ini key's holds an array so I'm not sure how to loop through that while still being able to parse an ini file and not overwriting the holder variable $built

Any help would really be appreciated!


You must first go and read about recursion. Just type the word into Google or even Wikipedia, you'll get the idea. Or just look for array_merge and array_merge_recursive at http://php.net, that's what you need. But first read about recursion anyway, you should know such basic things if you are going to write code further.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜