empty() is similar !$a

The function empty() determines whether a variable is considered to be empty. The following things are considered to be empty:

It’s the same list as for the things that make $a evaluate to false in an expression.

if (empty($sp[0])) {
  form_destroy();
  die('Subject phrases missing 467778777. -Programmer.');
}

I think this could have been written more simply as:

if (!$sp[0]) {
  form_destroy();
  die('Subject phrases missing 467778777. -Programmer.');
}

If you disagree then please comment below.

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in PHP Code Snippets, PHP Form Processing, PHP Language Constructs, PHP String and tagged , , , . Bookmark the permalink.

2 Responses to empty() is similar !$a

  1. Thanks for pointing that out:)

  2. Sam Dufel says:

    Sam,
    The difference between using empty($a[0]) and !$a[0] is that empty() will not generate a warning when $a[0] is not set. You won’t notice it with error reporting turned down, but if it’s set to E_WARNING or E_NOTICE it’ll start triggering errors.

Comment