Help with Array Mathematics
Moderator: General Moderators
- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
Help with Array Mathematics
Hi,
I need to add up variables as follows;
$oscost
$cpucost
$hddcost
and so on....
I cant for the life of me remember how to perform math functions...
Please help.
thanks in advance.
I need to add up variables as follows;
$oscost
$cpucost
$hddcost
and so on....
I cant for the life of me remember how to perform math functions...
Please help.
thanks in advance.
hmmm...
Code: Select all
<?php
$total = $oscost + $cpucost + $hddcost;
?>
Last edited by JayBird on Tue Jan 31, 2006 5:16 am, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
If it's an array you're adding up then use array_sum().
Code: Select all
<?php
$array = array(1, 2, 4, 8, 16);
echo array_sum($array); //31
?>- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
did this not work?Pimptastic wrote:hmmm...
Code: Select all
<?php $total = $oscost + $cpucost + $hddcost; ?>
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York