How can I check if the string variable is empty?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babansky
    New Member
    • Aug 2010
    • 7

    How can I check if the string variable is empty?

    How can i check if the string variable is empty?
    so that i the error undefined offset will not going to appear anymore?

    im doing a program that will output all of his children, then i cant do the code that if the string variable is empty they will not out put the row, if the string variable has something on it, it will out put the information and also add another row..

    thanks

    sorry for this kind of question
    i just need help

    thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Determine whether a variable is empty

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      As Markus suggested, empty() will do what you need.

      empty() is a combination of isset() and a check against the value. For strings, it checks that the value is not ''. For integers, it checks if the value is not 0. For booleans, it checks if the value is not false. For arrays, it checks if there are any indices.

      This is done on a very low level (empty is actually a language construct, like include) so the check is faster than doing it yourself.

      Comment

      Working...