Fall into the hole in PHP--null,0,false, empty string
When the update data was discovered today using the framework of the company, those empty strings were not updated in the database, that is, like 0, an empty string, and null these occurrences were not updated in the database:
When carefully debugged, I found that the function of empty () was used:
if (!empty ($params [' ID '])) { $filters [] = array (' id ', ' = ', $params [' id ']); }
Then naturally there is no such condition, to update the database, the pit how to fill it? Just do not use empty (), use Isset ():
if (Isset ($params [' config_id '])) { $filters [] = Array (' config_id ', ' = ', $params [' config_id ']); }
The difference between the two functions:
Look at the name of the light can be seen empty is to see if this variable is null, isset see if this variable is set:
In your own words:
Empty is to judge what is stored inside this variable is 0,null,false, an empty string.
Isset is whether this variable has been declared, it can be a 0,null,false, an empty string.
Empty has a larger range and a smaller range of isset.
If you want to be very precise: it is recommended to use ' = = = ', so that PHP will detect whether the type and value of the two variables are exactly like.
So emtpy,isset,=== need to see the use of the scene reasonable use.