<?php



function slidingWithForecast($arr,$step){


    $countValue = count($arr) + $step;
    $arr = array_values(array_diff($arr, array('0')));

    $step = $countValue - count($arr) + $step;


    $r = 0;
    while ($r < $step){
        $revArr = array_reverse($arr);
        $xNew = ($revArr[0] - $revArr[1]) + $revArr[0];
        if($xNew < 0){
            $xNew = 0;
        }
        array_push($arr,$xNew);
        $r++;
    }
    /*print_r($arr);
    echo '<br>';*/

    return arrSmoothing($arr);
}


function arrSmoothing($arr){
    $arrSm = array();
    array_push($arrSm, $arr[0]);
    $r = 1;
    while ($r < count($arr)){
        if(count($arrSm) > 1){
            $smValue = ($arrSm[$r - 1] + $arr[$r + 1]) / 2;
        }else{
            $smValue = ($arr[$r - 1] + $arr[$r + 1]) / 2;
        }
        array_push($arrSm, $smValue);
        $r++;
    }
    return $arrSm;
}














