Live chat Whatsapp
Live chat Whatsapp
Attiva Web - Realizzazione siti internet, ecommerce

Empty function of PHP, some more information

    • The empty function, native to the PHP programming language, is useful for checking if a certain pass-through value is empty or not.

      For example, if I want to check if the data passed from a form is empty I can write:

      if (! empty ($ _ POST [ 'miovalore']))
        //Do this
      else
        // do something else

      however, there is an important consideration that sometimes can escape (not for another write this article laugh), if for example in the form I have the numerical value 5 and I want to overwrite it with the value number 0, I could not get the expected result because the language PHP programming considers empty the following values:

          "" (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)

      therefore in certain operations (not always) I could not execute specific commands because the value 0 (zero) being considered empty does not allow me to enter a specific condition.

      I hope I have been helpful.
       

      Francesco // 11-02-2019 // PHP

    Lascia un commento

    Invia commento


    ATTENZIONE: il tuo commento verrà prima moderato e se ritenuto idoneo sarà pubblicato