I'm giving myself a headache trying to visualize it, but I'm pretty sure there's a recursive solution in there someplace...<br><br>SOMETHING like this...<br><br>function dimadd($flatarray, $val)<br>{<br> $x = array_shift($flatarray);<br>
if (empty($flatarray))<br> $m[$x] = $val;<br> else<br> $m[$x] = dimadd($flatarray);<br> return($m);<br>}<br><br>Having proposed that possible solution, it's obvious that it would not be kind to future maintainers so maybe best left in the theoretical box... :-)<br>
<br>An eval would make it very easy, but perhaps for security purposes you'd rather avoid that:<br><br>$x = '$multidim';<br>while ($a = array_shift($flatarray))<br> $x .= "[$a]";<br>$x .= " = '$val'";<br>
eval($x);<br><br>I can't think of any other way to do it right now. Maybe something with pointers/references (whatever they're called in php) where you build it up from left-to-right and create a reference to that one for each step along the way...? Again, in the highly theoretical and totally untested camp:<br>
<br>$multidim = array();<br>$ref = &$multidim;<br>while ($a = array_shift($flatarray)) {<br> $ref[$a] = array();<br> $ref = &$ref;<br>}<br><br>Note that I always get my pop/push and shift/unshift mixed up so I may be going from the wrong end on all these solutions. <br>
<br>Hope something here will help at least to get some ideas rolling.<br><br>-Peter<br><br><div class="gmail_quote">On Thu, Feb 5, 2009 at 3:48 PM, Hans <span dir="ltr"><<a href="mailto:design5@softflow.co.uk">design5@softflow.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">Thursday, February 5, 2009, 2:28:34 PM, Daniel wrote:<br>
<br>
> $string = "k1:k2:k3:...:kn";<br>
> $array = explode(":", $string);<br>
<br>
> //Contents of $array is now:<br>
> // Array<br>
> // {<br>
// [0] =>> k1<br>
// [1] =>> k2<br>
// [2] =>> k3<br>
> // ...<br>
// [n-1] =>> kn<br>
> // }<br>
<br>
> Avast!<br>
<br>
</div>I got so far, but the "avast!" defeats me. Perhaps I am thick ;-)<br>
<br>
How do I construct out of that nice flat array this array-element:<br>
<br>
n deep array $arr<br>
element needed<br>
$val = arr[$k[0]][$k[1]][$k[2]]....[$k[$n]];<br>
or element set<br>
$arr[$k[0]][$k[1]][$k[2]]....[$k[n]] = $val;<br>
<br>
How can the ... be constructed, with n being a variable integer?<br>
<br>
Thanks,<br>
<div><div></div><div class="Wj3C7c">Hans<br>
<br>
<br>
_______________________________________________<br>
pmwiki-devel mailing list<br>
<a href="mailto:pmwiki-devel@pmichaud.com">pmwiki-devel@pmichaud.com</a><br>
<a href="http://www.pmichaud.com/mailman/listinfo/pmwiki-devel" target="_blank">http://www.pmichaud.com/mailman/listinfo/pmwiki-devel</a><br>
</div></div></blockquote></div><br>