Difference between PHP if $variable, isset(), empty(), strlen() | |||||||||||
What is the difference between PHP functions below ? if ($variable) { } if (isset($variable)) { } if (!empty($variable)) { } if (strlen($variable)) { } | |||||||||||
| |||||||||||
Hi, The differences between those PHP functions are visible in specific cases. For example when variable is created, is NULL, is 0, is TRUE or FALSE etc. In the condition if ($variable) { echo "OK"; } the output will be OK when $variable:
In the condition if (isset($variable)) { echo "OK"; } the output will be OK when $variable:
In the condition if (!empty($variable)) { echo "OK"; } the output will be OK when $variable:
In the condition if (strlen($variable)) { echo "OK"; } the output will be OK when $variable:
In relation to these functions, you can use is_null() to find out if variable is NULL. | |||||||||||
| |||||||||||
| |||||||||||
![]() ![]() ![]() ![]() | |||||||||||
2022 AnswerTabs | Terms | Contact us |