RE: [PHP] Count of multi-dimensional array

From: Date: Sun, 18 Feb 2001 15:14:39 +0000
Subject: RE: [PHP] Count of multi-dimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40421@lists.php.net to get a copy of this message
it's not very elegant, but i havent come across any PHP core function that will do what you asked, so here's a little loop that will return the total length of a multidimensional array $total = 0; for ($i=0; $i < count($myarray); $i++) { $total += count( $myarray[$i] ); } print $total; in your case, it will (should) print "8" > -----Original Message----- > From: Rasmus Lerdorf [mailto:rasmus@php.net] > Sent: Saturday, February 17, 2001 09:52 > To: bill > Cc: php-general@lists.php.net > Subject: Re: [PHP] Count of multi-dimensional array > > > count($myarray) will give you 3 > > On Sat, 17 Feb 2001, bill wrote: > > > How can i get the count of a multi-dimensional array? > > > > if I have > > > > $myarray[0][chicken] > > $myarray[0][fish] > > $myarray[0][meat] > > $myarray[1][fries] > > $myarray[1][chips] > > $myarray[2][coke] > > $myarray[2][pepsi] > > $myarray[2][rootbeer] > > > > How can I get the number of first elements (which would be 3 above)? > > > > thanks, > > > > bill > >

« previous php.general (#40421) next »