Fill an array with last non-zero element to the end in PHP
Do you really want this function to use loose comparison $array[$i] != 0?  What should intended behavior be for other potentially falsey values at the end of the array (false, "", [], etc.)?  If you truly only want to replace only trailing zeroes, then you must use exact comparison here !==.
Your function name seems unclear with regards to what the function does.  Perhaps arrayPadOverTrailingZeroes, arrayPadOverTrailingEmptyValues (depending on desired behavior).
PHP provides built-in array functions that may clean up this code a little bit (and perhaps perform slightly better since they are compiled).


For example:

function arrayPadOverTrailingZeroes($array) {
    $length = count($array);
    while (($value = end($array)) === 0) {
        array_pop($array);
    }
    // This conditional to support case where you have all zeroes,
    // in which case, the while loop above would have discarded all array members
    // and $value would be set to false
    if (count($array) === 0) {
        $value = 0;
    }
    return array_pad($array, $length, $value);
}


Answered this before I saw your all-zeroes use case.  Added some additional logic above to handle this case.