How does preg_match function in PHP work when no matches and flags are specified?

When preg_match function in PHP is called without specifying any flags and no matches are found, it returns 0. To solve this issue, you can check the return value of preg_match and handle the case where no matches are found accordingly.

$subject = "Hello, World!";
$pattern = "/foo/";

if(preg_match($pattern, $subject)){
    echo "Match found!";
} else {
    echo "No match found.";
}