Steven Hammons
Steven Hammons

Reputation: 1810

How to tell if variable is empty?

<?php
echo $Variable;
?>

**//  I would like to check if the variable is empty, using but if() statements but more secure     than...**
  if($var == "")

is it possible to check if variable is empty more secure than this ?

Upvotes: 2

Views: 2940

Answers (5)

Paulraj
Paulraj

Reputation: 3397

using isset

Upvotes: 1

greg606
greg606

Reputation: 491

If (!isset($var) || empty($var))

Upvotes: 2

yogsma
yogsma

Reputation: 10586

Try this isset as a function

isset($variable)

Upvotes: 1

rrrhys
rrrhys

Reputation: 654

if(!isset($var) || $var == "")
{
    //$var is empty.
}

^ Thats what I use, it also covers if you haven't 'initialised' it yet.

*edit - to reflect comments

Upvotes: 6

Bart S.
Bart S.

Reputation: 11507

empty()

Upvotes: 8

Related Questions