[ create a new paste ] login | about

Link: http://codepad.org/EZEJB3EF    [ raw code | output | fork ]

PHP, pasted on Dec 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

$path = "group1.group2.group3.element";
$value = 55;

$x = explode(".",$path);

$result = Array();
$last = &$result;
foreach ($x as $elem) {
    $last[$elem] = Array();
    $last = &$last[$elem];
}
$last = $value;

echo("<pre>$path=$value");
print_r($result);


?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<pre>group1.group2.group3.element=55Array
(
    [group1] => Array
        (
            [group2] => Array
                (
                    [group3] => Array
                        (
                            [element] => 55
                        )

                )

        )

)


Create a new paste based on this one


Comments: