RE: [PHP] Counting Multidimensional Arrays
| From: | Tim Ward | Date: | Wed, 01 Aug 2001 08:08:35 +0000 |
| Subject: | RE: [PHP] Counting Multidimensional Arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-60579@lists.php.net to get a copy of this message | ||
I assume that
$m = 07;
$y = 2001;
$d = 31;
echo count($this->arrEvents[$y][$m][$d]);
is in a method of the class that $someclass is a method of, something like:
class fred
{
function dispcount()
{ $m = 07;
$y = 2001;
$d = 31;
echo count($this->arrEvents[$y][$m][$d]);
}
}
$Events[2001][07][31][0] = 12;
$Events[2001][07][31][1] = 13;
$Events[2001][07][31][2] = 45;
$Events[2001][08][01][0] = 35;
$someclass = new fred();
$someclass->arrEvents = $Events;
$someclass->dispcount();
this works, is your code working differently to this?
Tim
----------
From: Johnny Nguyen [SMTP:johnny@zugara.com]
Sent: 31 July 2001 23:58
To: php-general@lists.php.net
Subject: [PHP] Counting Multidimensional Arrays
Given
////////////////////////////////////////////////////////////////////////////
//////////////
$Events[2001][07][31][0] = new ZEvent("Some Event 0", "Some
Description 0",
"07-31-2001");
$Events[2001][07][31][1] = new ZEvent("Some Event 1", "Some
Description 1",
"07-31-2001");
$Events[2001][07][31][2] = new ZEvent("Some Event 2", "Some
Description 2",
"07-31-2001");
$Events[2001][08][01][0] = new ZEvent("Some Event 0", "Some
Description 0",
"08-01-2001");
if I set.
$someclass->arrEvents = $Events;
and then inside of some class i say.
$m = 07;
$y = 2001;
$d = 31;
echo count($this->arrEvents[$y][$m][$d]);
Shouldn't I get 3 as my output? For some reason I am getting 0.
However, if I do:
foreach ($someclass->arrEvents[2001][07][31] as $someevent) {
echo $someevent->getName();
}
I get the correct output:
"Some Event 0Some Event 1Some Event 2"
Any ideas on how to get the correct count within someclass?
Regards,
Johnny Nguyen