you need to count all the elements in each of the elements. $x is a simple
array each member of which is an array
<?php
function ArraySize($Array)
{ $count = 0;
foreach($Array as $Element)
{ if (is_array($Element))
{ $count += ArraySize($Element);
} else
{ $count++;
}
}
return $count;
}
?>
this should work for any array, although for some reason it falls over if
the array passed in hasn't been predfined as an array.
i.e.
<?php
$fred = array();
$fred[1][1][1] = 5;
$fred[1][2][3] = 5;
$fred[2][2][3] = 5;
echo(ArraySize($fred));
?>
... works
but ...
<?php
$fred[1][1][1] = 5;
$fred[1][2][3] = 5;
$fred[2][2][3] = 5;
echo(ArraySize($fred));
?>
... doesn't. I haven't worked out why, yet.
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: Chris Anderson [mailto:[EMAIL PROTECTED]]
> Sent: 25 April 2001 01:31
> To: PHP
> Subject: Sizeof a multi-dimensional array??
>
>
> Alright, count($x) would give me the number of array elements
> in $x. But how can I get the count of a multi-dimensional
> array? Count($x[0]) doesn't seem to work. Thanks in advance
>
> Chris Anderson aka "Null"
> --------------------------------------------
> PHP Developer / Nulltech
> PHP-GTK Tester / gtk.php.net
> STA Administrator / www.stronger.org
> DOD Co-Owner / www.dayofdefeat.com
>
>
--
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]