Search code examples
phpternary-operator

Simple PHP isset test


This below does not seem to work how I would expect it, event though $_GET['friendid'] = 55 it is returning NULL

<?PHP

$_GET['friendid'] = 55;

$friendid = (!isset($_GET['friendid'])) ? $_GET['friendid'] : 'empty';

echo $friendid;
exit;

?>

Solution

  • Remove the !. You don't want to negate the expression.

    $friendid = isset($_GET['friendid']) ? $_GET['friendid'] : 'empty';