Answer the question
In order to leave comments, you need to log in
What is the difference between empty() and !?
Which method is better to use for checking if a variable is empty: if ( empty($foo) )
or if ( !$foo )
And similarly, checking if a variable is not empty: if ( !empty($foo) )
or just if ( $foo )
As far as I know, using empty and just ! before the variable, they check the same thing (check for an empty string / 0 / null / false / empty array), i.e. the result is the same, but what is more relevant to use on php 7.1?
Answer the question
In order to leave comments, you need to log in
You are wrong, they work differently. Here you can study the table how different check methods work empty, is_null, isset, boolean, if($x) - php.net/manual/en/types.comparisons.php
What to use should be based on the logic of your code and this table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question