![]() However, it’s shorter you use the empty() construct: ! empty($data) Code language: PHP ( php ) Summary To check if the $data array has an element with the key 'username' and it is not empty, and you may use the following expression: isset($data) & $data != '') Code language: PHP ( php ) ![]() In practice, you use the empty() construct in the situation that you’re not sure if a variable even exists.įor example, suppose you receive an array $data from an external source, e.g., an API call or a database query. ![]() } Code language: PHP ( php ) When to use the PHP empty() construct The following returns true for all the falsy values in the $falsy_values array:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |