Jump to content

[SOLVED] array sum


Minase

Recommended Posts

$d = 51;
while ($d <= 60) {
$costs2 =($d++ - 4 );
$costs1 = pow($costs2, 2.6);
$coststr = (int) $costs1;
$da = $coststr.",\n";
$dd = array($da);
foreach ($dd as &$value) {
    $value = $value * 2;
}

echo $value."\n";

 

i have the above code,how can i make the sum of all arrays?

cause its just returning the normal ones

i want to have a variable that has the final answer in it

here is what is curently return

44512 47016 49606 52280 55044 57894 60834 63862 66984 70196

i want a sum of those all numbers how can i do it? thank you.

Link to comment
https://forums.phpfreaks.com/topic/107981-solved-array-sum/
Share on other sites

<?php
$d = 51;
$total = 0;
while ($d <= 60) {
$costs2 =($d++ - 4 );
$costs1 = pow($costs2, 2.6);
$coststr = (int) $costs1;
$da = $coststr.",\n";
$dd = array($da);
foreach ($dd as &$value)
{
    $value = $value * 2;
}
echo $value."\n";
$total = $total + $value;
}
echo "total = $total\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/107981-solved-array-sum/#findComment-553487
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.