How can nested conditional logic affect the functionality of preg_match() in PHP?

Nested conditional logic can complicate the regular expression pattern used in preg_match(), potentially leading to unexpected results or errors. To avoid this issue, it is recommended to break down the logic into simpler conditions and use separate preg_match() calls for each condition.

// Example of breaking down nested conditional logic
$string = "Hello World";

// Check for "Hello" followed by "World"
if (preg_match("/Hello/", $string) && preg_match("/World/", $string)) {
    echo "Both 'Hello' and 'World' found in the string.";
}

// Check for "Hello" or "World"
if (preg_match("/Hello|World/", $string)) {
    echo "Either 'Hello' or 'World' found in the string.";
}