actually a nested foreach() is probably better. Use it in a function that
calls itself recursively for all elements that are arrays and adds to the
count for all that aren't.

I posted a function that does this a little while ago, don't think I've got
it anymore but the idea is fairly straightforward.

The key to dealing with multi-dimensional arrays is in realising that they
don't exist. In your example you have an array with a single element. That
element is itself an array with 4 elements. Any one (or all) of these
elements could be another array, hence the need for a recursive function to
find the elements in a multi-dimensional array.

        Tim Ward
        Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 07 May 2001 18:12
> To: Brandon Orther; PHP User Group
> Subject: Re: [PHP] Multi Dimensional Arrays?
> 
> 
> I would have to say you would need a nested for loop to count 
> your array.
> 
> $j =  0 ; 
> $k = 0 ;
> 
> for ( ; $j != '' ) ; $j++  )
> {
> 
>             //top of the col.
>             echo "$main_menu[$j][$k]<br>";
> 
>             for ( $k =  1; $k != '' ; $k++  ) 
>             {
>                     // then everything under the col (by row)
>                       echo "$main_menu[$j][$k]<br>";
>             }
> }
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "Brandon Orther" <[EMAIL PROTECTED]>
> To: "PHP User Group" <[EMAIL PROTECTED]>
> Sent: Monday, May 07, 2001 8:59 AM
> Subject: [PHP] Multi Dimensional Arrays?
> 
> 
> Hello,
> 
> I am working on a menu script that I wanted to use 
> multi-dimensional arrays
> for.
> 
> Here is the conf file I have:
> 
> //Main Menu Array
> $main_menu[0] = "Menu 1";  //Represents the name of the menu
> 
> //Menu 1 Array
> $main_menu[0][0] = "Test 1";
> $main_menu[0][1] = "Test 2";
> $main_menu[0][2] = "Test 3";
> $main_menu[0][3] = "Test 4";
> 
> When I try to us count like:
> 
> $count = count($main_menu[0]);
> 
> I only get 1.  My question is how do I count a multi 
> dimensional array.
> 
> Thanks for the help,
> Brandon
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: 
> [EMAIL PROTECTED]
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to