Mike Liss wrote:
> Ok,
>
> I think I am beginning to see the light...
> but I am still in the dark on this one...
>
> How would I iterate over these arrays?
>
> $MyArray[0][0][0] = "A 1";
> $MyArray[0][1][0] = "comment 1";
>
> $MyArray[0][0][1] = "A 2";
> $MyArray[0][1][1] = "Comment 2";
>
> $MyArray[1][0][0] = "B 1";
> $MyArray[1][1][0] = "comment 1";
>
> $MyArray[1][0][1] = "B 2";
> $MyArray[1][1][1] = "Comment 2";
>
>
> for example I could do this:
>
> for( $i=0; $i<$n; $i++ )
> {
>     for( $j=0; $j<$m; $j++ )
>     {
>         for( $k=0; $k<$p; $k++ )
>         {
>             print " $MyArray[ $i ][ $j ][ $p ] \n" ;

You mean:

               print " $MyArray[ $i ][ $j ][ $k ] \n" ;

>         }
>     }
> }
>
> But the problem with that is I don't know what n, m, and p are going
> to be...

The sensible way to dump the entire 3D array is:

    foreach (@MyArray) {
        foreach (@$_) {
            foreach (@$_) {
                print "$_\n";
            }
        }
    }

output

    A 1
    A 2
    comment 1
    Comment 2
    B 1
    B 2
    comment 1
    Comment 2

But that isn't the order your code assigned them, which increments the
2nd index followed by the 3rd followed by the first. Here they are
printed in the order 3, 2, 1 as you'd expect.

Cheers,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to