RE: [PHP] Re: how to sum array items, vertically?
| From: | Martin Towell | Date: | Wed, 23 Jan 2002 04:07:33 +0000 |
| Subject: | RE: [PHP] Re: how to sum array items, vertically? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-81634@lists.php.net to get a copy of this message | ||
I can't see any other way other than a manual loop...
-----Original Message-----
From: Siggy [mailto:sigurd@totallydigital.co.nz]
Sent: Wednesday, January 23, 2002 3:03 PM
To: php-general@lists.php.net
Subject: [PHP] Re: how to sum array items, vertically?
Hmm, am a little confused by var_dump; am used to print_r which seems to be
different.
The code is basically:
$everything [ $date ] = array(10, 20, 30, 40);
where $date is simply a text string like "01/01/2001";
Eg:
array(4) {
["07/01/2002"]=> array(3) {
[6]=> int(7200)
[5]=> int(17400)
[1]=> int(22500)
}
["14/01/2002"]=> array(4) {
[1]=> int(77400)
[4]=> int(83700)
[5]=> int(77400)
[6]=> int(144300)
}
["21/01/2002"]=> array(4) {
[1]=> int(63900)
[4]=> int(81900)
[5]=> int(105000)
[6]=> int(92400)
}
["23/01/2002"]=> array(4) {
[1]=> int(35100)
[4]=> int(18000)
[5]=> int(38100)
[6]=> int(55500)
}
}
Siggy
----- Original Message -----
From: Martin Towell
To: 'Sigurd'
Sent: Wednesday, January 23, 2002 4:23 PM
Subject: RE: [PHP] how to sum array items, vertically?
is this the exact array constructor ?? if I do a var_dump() on it I get:
array(12) {
["Monday"]=> int(1)
[0]=> int(4)
[1]=> int(1)
[2]=> int(0)
["Tuesday"]=> int(5)
[3]=> int(0)
[4]=> int(0)
[5]=> int(0)
["Sunday"]=> int(2)
[6]=> int(2)
[7]=> int(3)
[8]=> int(1)
}
I don't think that's what you mean, is it?
-----Original Message-----
From: Sigurd [mailto:sigurd@totallydigital.co.nz]
Sent: Wednesday, January 23, 2002 12:28 AM
To: php-general@lists.php.net
Subject: [PHP] how to sum array items, vertically?
Assuming my array of this variety:
array(
"Monday" => 1, 4, 1, 0,
"Tuesday" => 5, 0, 0, 0,
"Sunday" => 2, 2, 3, 1);
How do I sum, vertically, the numbers; short of traversing thru the array
and doing it manually ? I thought about doing a array_flip() but that
didnt
work. I want this:
array(
1 => 7,
2 => 6,
3 => 4,
4 => 1);
Siggy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net