Why do I keep getting errors generating PDF with TCPDF in PHP when handling empty values in the R field?

while ($row = mysqli_fetch_assoc($result)) {
    $html .= '<tr style="font-family: times; color: black; font-size: 0.9em;">';
    $html .= '<td style="width:6%; border: 1px solid black;">' . $row['codeFonctionnel'] . '</td>';
    $html .= '<td style="width:6%; border: 1px solid black;">' . $row['codeEco'] . '</td>';
    $html .= '<td style="width:15%; border: 1px solid black;">' . $row['niveauR'] . '</td>';

    if ($row['niveauR'] == 'DEP') {
        $html .= '<td style="width:15%; border: 1px solid black;">-</td>'; // Print "-" for R
    } elseif ($row['niveauR'] == 'PRG') {
        $rValue = substr($row['R'], 10); // Get R value after 1211010000
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'REG') {
        $rValue = substr($row['R'], 16); // Get R value after 1211010000920
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'PRJ') {
        $rValue = substr($row['R'], 20); // Get R value after 121101000092000
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'LIN') {
        $rValue = substr($row['R'], 22); // Get R value after 12110100009200010
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    }

    $html .= '<td style="width:43%; border: 1px solid black;">' . $row['lib'] . '</td>';
    $html .= '<td style="width:15%; border: 1px solid black;">' . $row['CP'] . '</td>';
    $html .= '</tr>';
}

this is the error i get :

Fatal error: Uncaught ValueError: max(): Argument #1 ($value) must
contain at least one element in
C:xampphtdocstestcommandetcpdf.php:6412 Stack trace: #0
C:xampphtdocstestcommandetcpdf.php(6412): max(Array) #1
C:xampphtdocstestcommandetcpdf.php(18592): TCPDF->Write(4.7625,
‘xEFxBFxBD’, ”, 0, ”, false, 0, true, true, 0, 0) #2
C:xampphtdocstestcommandetcpdf.php(5930):
TCPDF->writeHTML(‘[]</c…’, true, false, true, true, ”) #3
C:xampphtdocstestcommandetcpdf.php(18372):
TCPDF->MultiCell(81.698987111111, 0, ‘[]</c…’, false, ”,
false, 2, 89.800260666667, 95.927333333333, true, 0, true, true, 0,
‘T’, false) #4 C:xampphtdocstestcommandeexportPDF.php(136):
TCPDF->writeHTML(‘<div style=”tex…’, true, false, true, false, ”)
#5 {main} thrown in C:xampphtdocstestcommandetcpdf.php on line 6412

I added a ternary operator (?:) to handle empty values in the R field.