user3196569
user3196569

Reputation: 55

What is the use of 'isset' in PHP?

if (isset($_GET['user_name']) && !empty($_GET['user_name']))

In the above code what is the use of the part - (isset($_GET['user_name'])

Upvotes: 0

Views: 569

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31749

isset will check if $_GET['user_name'] is set and is not NULL. But if you are using !empty($_GET['user_name']), there is no need for isset() as empty() will take care of it.

Only if (!empty($_GET['user_name'])) will check if $_GET['user_name'] is set and it contains a value.

NOTE: empty() will return true for -

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • $var; (a variable declared, but without a value)

empty() & isset()

Upvotes: 2

Related Questions