instead of:

    $checksum = (int) $check[17]; 

? If the objective it to cast checksum to an int - just cast it to an int.