Page 1 of 1
Help with Array Mathematics
Posted: Tue Jan 31, 2006 5:12 am
by mhouldridge
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.
Posted: Tue Jan 31, 2006 5:15 am
by JayBird
hmmm...
Code: Select all
<?php
$total = $oscost + $cpucost + $hddcost;
?>
Posted: Tue Jan 31, 2006 5:16 am
by Jenk
Posted: Tue Jan 31, 2006 7:45 am
by Chris Corbyn
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
?>
Posted: Tue Jan 31, 2006 9:04 pm
by nickman013
Pimptastic wrote:hmmm...
Code: Select all
<?php
$total = $oscost + $cpucost + $hddcost;
?>
did this not work?
Posted: Tue Jan 31, 2006 9:07 pm
by timvw
Posted: Tue Jan 31, 2006 9:08 pm
by nickman013
there you go, that should solve you problem if you didnt come across it already.
let us know how you made out.
Posted: Tue Jan 31, 2006 9:55 pm
by Christopher
Mathmaticians do it on matrices ...

Posted: Wed Feb 01, 2006 9:31 am
by raghavan20
I am very curious to know what the question is...is it just about addition of numbers...

Posted: Wed Feb 01, 2006 3:23 pm
by nickman013
I would assume it is numbers, because his variables have "cost" in it. I am not %100 positive though.