Here's another suggestion. Maybe helpful if you are looking in a specific POST value such as 'foo'. Above, HelpNeeder introduced the filter_input() function, great for filtering user input.
//php 8.1
// example.com?foo=bar
$query = 'bar';
if (filter_has_var($_SESSION['REQUEST_METHOD']))
{
$test = filter_input(INPUT_POST, 'foo', FILTER_SANITIZE_SPECIAL_CHARS);
if (null != $test && $query === $test)
{
//...
}
}