How does creating a function for an if-else construct impact the scope in PHP?
Creating a function for an if-else construct in PHP can help improve code readability and maintainability by encapsulating the logic within a reusable function. However, it's important to consider the scope of variables when using functions. Variables defined outside the function are not accessible within the function unless explicitly passed as parameters.
// Example of creating a function for an if-else construct in PHP
function checkNumber($number) {
if ($number % 2 == 0) {
echo "The number is even.";
} else {
echo "The number is odd.";
}
}
$myNumber = 10;
checkNumber($myNumber);