Search code snippets, questions, articles... Chrome Extension

Check empty string in PHP

if (empty($str)) {
   echo "String is empty";
} else {
   echo "String is not empty"
}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

To check whether a string is empty or not you can use the empty() function in PHP. As in the above code, we have passed a PHP variable named $str in empty() function if the string does not contain any value it will print 'String is empty and if it contains any character it will print 'String is not empty.

Below values are treated as empty

  • 0, 0.0, "0"
  • ""
  • null
  • false
  • array()

Search Index Data (The code snippet can also be found with below search text)

Check if string is null or empty
Was this helpful?
0 Comments
Join Devsheet Ask a Question