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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.