使用foreach增加变量

I want to increment a variable with a foreach loop. I save data in a session and for each data piece I make an if statement to check the dimensions and connect it to a price. Then I need to increment these prices in the variable $pr_total_str_saving.

Can someone help me with this?

if(isset($_SESSION['straight_saving'])) : 

    foreach($_SESSION['straight_saving'] as $key => $val) {

        if($val['wz_saving_a'] >= 1 && $val['wz_saving_a'] <= 300) :
            $str_saving_price = 25;
        elseif($val['wz_saving_a'] >= 301 && $val['wz_saving_a'] <= 500) :
            $str_saving_price = 39;
        endif;

        $pr_total_str_saving + $str_saving_price;

    }

    echo $pr_total_str_saving;

endif;

I believe you're looking for the += operator. Here's how you could use it:

$pr_total_str_saving += $str_saving_price;
if(isset($_SESSION['straight_saving'])) : 

$pr_total_str_saving = 0;

foreach($_SESSION['straight_saving'] as $key => $val) {

    if($val['wz_saving_a'] >= 1 && $val['wz_saving_a'] <= 300) :
        $str_saving_price = 25;
    elseif($val['wz_saving_a'] >= 301 && $val['wz_saving_a'] <= 500) :
        $str_saving_price = 39;
    endif;

    $pr_total_str_saving += $str_saving_price;

}

echo $pr_total_str_saving;

endif;