How can a PLZ-Matching function be implemented in PHP for a logistics tool?

To implement a PLZ-Matching function in PHP for a logistics tool, you can use regular expressions to validate and match postal codes (PLZ) against a given pattern. This function can be used to check if a given PLZ matches a specific format or range, which can be helpful in logistics for sorting and routing purposes.

function matchPLZ($plz, $pattern) {
    if (preg_match($pattern, $plz)) {
        return true;
    } else {
        return false;
    }
}

$plz = "12345"; // PLZ to match
$pattern = "/^\d{5}$/"; // Pattern for 5-digit PLZ

if (matchPLZ($plz, $pattern)) {
    echo "PLZ $plz matches the pattern.";
} else {
    echo "PLZ $plz does not match the pattern.";
}