[pmwiki-devel] php multi-dimensional array construction problem

Daniel Roesler diafygi at gmail.com
Thu Feb 5 09:12:20 CST 2009


On Thu, Feb 5, 2009 at 8:48 AM, Hans <design5 at softflow.co.uk> wrote:
>
> I got so far, but the "avast!" defeats me. Perhaps I am thick ;-)

Ha, Avast! is my signature, not php, but you're probably being sarcastic.

>
> How do I construct out of that nice flat array this array-element:
>
> n deep array $arr
> element needed
>   $val = arr[$k[0]][$k[1]][$k[2]]....[$k[$n]];
> or element set
>   $arr[$k[0]][$k[1]][$k[2]]....[$k[n]] = $val;
>
> How can the ... be constructed, with n being a variable integer?

I'm not really sure what you're asking. The ellipses (...) are just
there to show a continuation. The n'th element is simply the last
element. For example:

$string = "k1:k2:k3:k4:k5";
$array = explode(":", $string);

//Contents of $array is now:
// Array
// {
//    [0] => k1
//    [1] => k2
//    [2] => k3
//    [3] => k4
//    [4] => k5
// }

You can get a particular value by calling that element in the array.
For example, if you want to get k4:

$val = $array[3];

The array location is one less because the array keys start numbering from zero.

Avast!
Daniel Roesler
diafygi at gmail.com



More information about the pmwiki-devel mailing list