Differences between using! empty or! == ""

0

What would be the difference between validating states in two ways:

if(!empty($_POST['miName']{
}

if($_POST['miName'] !== ""{
}
    
asked by AndresGonzalez 10.04.2018 в 00:58
source

1 answer

0

With empty you can include this:

  • "" (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 declared variable, but without a value)

Quoting the response of @ J.Correa in the publication How and when are isset () and empty () used correctly?

And with ! == "" you are strictly comparing both sides for your VALUE and TYPE. The result will be true if VALUE or TYPE is inconsistent, in which you will be validating if in _ $ POST there is an empty string

    
answered by 10.04.2018 в 01:26