I&#39;m giving myself a headache trying to visualize it, but I&#39;m pretty sure there&#39;s a recursive solution in there someplace...<br><br>SOMETHING like this...<br><br>function dimadd($flatarray, $val)<br>{<br>&nbsp;&nbsp; $x = array_shift($flatarray);<br>
&nbsp;&nbsp; if (empty($flatarray))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $m[$x] = $val;<br>&nbsp;&nbsp; else<br>&nbsp; &nbsp; &nbsp; $m[$x] = dimadd($flatarray);<br>&nbsp;&nbsp; return($m);<br>}<br><br>Having proposed that possible solution, it&#39;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&#39;d rather avoid that:<br><br>$x = &#39;$multidim&#39;;<br>while ($a = array_shift($flatarray))<br>&nbsp;&nbsp; $x .= &quot;[$a]&quot;;<br>$x .= &quot; = &#39;$val&#39;&quot;;<br>
eval($x);<br><br>I can&#39;t think of any other way to do it right now.&nbsp; Maybe something with pointers/references (whatever they&#39;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...?&nbsp; Again, in the highly theoretical and totally untested camp:<br>
<br>$multidim = array();<br>$ref = &amp;$multidim;<br>while ($a = array_shift($flatarray)) {<br>&nbsp;&nbsp; $ref[$a] = array();<br>&nbsp;&nbsp; $ref = &amp;$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.&nbsp; <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">&lt;<a href="mailto:design5@softflow.co.uk">design5@softflow.co.uk</a>&gt;</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>
&gt; $string = &quot;k1:k2:k3:...:kn&quot;;<br>
&gt; $array = explode(&quot;:&quot;, $string);<br>
<br>
&gt; //Contents of $array is now:<br>
&gt; // Array<br>
&gt; // {<br>
// &nbsp; &nbsp;[0] =&gt;&gt; k1<br>
// &nbsp; &nbsp;[1] =&gt;&gt; k2<br>
// &nbsp; &nbsp;[2] =&gt;&gt; k3<br>
&gt; // &nbsp; &nbsp;...<br>
// &nbsp; &nbsp;[n-1] =&gt;&gt; kn<br>
&gt; // }<br>
<br>
&gt; Avast!<br>
<br>
</div>I got so far, but the &quot;avast!&quot; 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>
 &nbsp; $val = arr[$k[0]][$k[1]][$k[2]]....[$k[$n]];<br>
or element set<br>
 &nbsp; $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>