Câu hỏi phỏng vấn PHP
Câu hỏi

Is there a difference between isset and !empty ?

Câu trả lời

Certainly! Here's a detailed answer to your question:

Difference between isset() and !empty()

In PHP, both isset() and !empty() are used to check the existence and value of a variable, but they have some key differences:

1. Checking for null values

  • isset() returns true if a variable is set and is not null.
  • !empty() returns false if a variable is null.

Example:

php Copy
$variable = null;
var_dump(isset($variable)); // Output: bool(false)
var_dump(!empty($variable)); // Output: bool(false)

2. Checking for empty values

  • isset() returns true even if the variable is set to a value that is considered empty (e.g., 0, "0", false, null, array(), or an empty string "").
  • !empty() returns false if the variable is set to a value that is considered empty.

Example:

php Copy
$variable = 0;
var_dump(isset($variable)); // Output: bool(true)
var_dump(!empty($variable)); // Output: bool(false)

3. **Checking for undefined vari...

junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What is stdClass in PHP?

middle

What are some of the big changes PHP has gone through in the past few years?

senior

Store an array as JSON or as a PHP serialized array?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào