How can the if-else statement in the PHP function be optimized to handle both POST and GET requests without differentiation?
To handle both POST and GET requests without differentiation in a PHP function, you can use the `$_REQUEST` superglobal variable instead of checking `$_POST` and `$_GET` separately. This variable contains the values of both `$_POST` and `$_GET` arrays, allowing you to access request parameters regardless of the request method used.
function handleRequest() {
$data = $_REQUEST['data'];
if(isset($data)) {
// Handle the data from the request
echo "Data received: " . $data;
} else {
echo "No data received";
}
}
handleRequest();