What is += used for?

I think this is a dumb question but I could not find it on php. Why is a + with the = in the following code:

function calculateRanking()
{
    $created = $this->getCreated();

    $diff = $this->getTimeDifference($created, date('F d, Y h:i:s A'));

    $time = $diff['days'] * 24;
    $time += $diff['hours'];
    $time += ($diff['minutes'] / 60);
    $time += (($diff['seconds'] / 60)/60);

    $base = $time + 2;        

    $this->ranking = ($this->points - 1) / pow($base, 1.5);

    $this->save();
}

Is this so $time has all those values or rather it is adding all the values to $time?

Thanks


It's adding all those values to time.

something += somethingelse

is a shortcut for

something = something + somethingelse

-Adam


$time += $diff['hours'];

就像说的一样

$time = $time + $diff['hours'];

a += 2; is the equivalent of a = a + 2;

At one time with some languages (especially very old C compilers), the compiler produced better code with the first option. It sticks around now because it's a common idiom and people used to it think it's clearer.

链接地址: http://www.djcxy.com/p/1824.html

上一篇: = 1`在我的PHP文件中是什么意思?

下一篇: 什么是+ =用于?