-3

Which is the more effective way of checking whether $value is not null

if ($value > 0 && $value !== 'null') { }

or

if (empty($value)) { }
Mureinik
  • 297,002
  • 52
  • 306
  • 350
black999
  • 11
  • 1

2 Answers2

2

PHP has an elegant is_null function to check if a variable is actually NULL.

if (is_null($value)) {
    // so something
}

empty, on the other hand, checks for empty strings (''), zeroes (as integers, floating points or even the string '0'), FALSE, empty arrays, uninitialized variables and NULLs.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
-1
if(!empty($value)){
 //do stuff
}else{
// do somthing else
}
Tariq hussain
  • 614
  • 5
  • 11
  • 3
    Please consider adding at least some words explaining to the OP and to further readers of you answer why and how it does reply to the original question. – β.εηοιτ.βε Jul 01 '15 at 20:56