Re: Multidimensional arrays (more and more...)
| From: | Paul Chvostek | Date: | Thu, 28 Nov 2002 18:27:56 +0000 |
| Subject: | Re: Multidimensional arrays (more and more...) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126529@lists.php.net to get a copy of this message | ||
On Thu, Nov 28, 2002 at 10:19:38AM -0800, Mako Shark wrote:
...
> My problem is I need to loop through these. So I can't
> just assume that the count is count($issue[]) divided
> by 8, because that won't work in a for loop. I suppose
> I could just iterate through my for loop in jumps of
> 8, but that seems really hacky and unintuitive to
> whomever has to figure out my code when I'm gone.
By your description, count($issue)/count($issue[]) is the number of
real elements. And a foreach loop will correctly step through whatever
array you pass to it, even if the values of that array are themselves
arrays. Or could you try something like count(array_keys($issue)) ...
or the loop could be as simple as:
$count=0; foreach($issue as $junk) $count++;
which is clear, though to my eye is the same as count();
I'm surprised that count($issue) would report something other than the
number of elements in $issue. I never count my multidimensional arrays
so it's never come up for me. :-/
--
Paul Chvostek <paul@it.ca>
Operations / Abuse / Whatever +1 416 598-0000
it.canada - hosting and development http://www.it.ca/