how to merge multiple url/path into multidimensional array ?

Posted by KelNoReem on Stack Overflow See other posts from Stack Overflow or by KelNoReem
Published on 2010-04-05T15:47:01Z Indexed on 2010/04/05 15:53 UTC
Read the original article Hit count: 614

Filed under:
|
|
|
|

I have array like this:

$path = array (
[0] => site\projects\terrace_and_balcony\mexico.jpg
[1] => site\projects\terrace_and_balcony\new_york.jpg
[2] => site\projects\terrace_and_balcony\berlin.jpg
[3] => site\projects\terrace_and_balcony\Kentucky.jpg
[4] => site\projects\terrace_and_balcony\Utah.jpg
[5] => site\projects\terrace_and_balcony\Hawaii.jpg
[6] => site\projects\private_gardens\mexico.jpg
[7] => site\projects\private_gardens\new_york.jpg
[8] => site\projects\private_gardens\berlin.jpg
[9] => site\projects\private_gardens\Kentucky.jpg
[10] => site\projects\private_gardens\Utah.jpg
[11] => site\projects\private_gardens\Hawaii.jpg
)

How to convert it to that:

$path11 = array
(
    "site"=>array
    (
        "projects"=>array
        (
            "terrace_and_balcony"=>array
            (
                "mexico.jpg",
                "new_york.jpg",
                "berlin.jpg",
                "Kentucky.jpg",
                "Utah.jpg",
                "Hawaii.jpg"
            ),
            "private_gardens"=>array
            (
                "mexico.jpg",
                "new_york.jpg",
                "berlin.jpg",
                "Kentucky.jpg",
                "Utah.jpg",
                "Hawaii.jpg"
            )
        )
    )
);

© Stack Overflow or respective owner

Related posts about php

Related posts about merge