echo json_encode (0). "
"; Output "0" echo json_encode (null). "
"; Output "null" echo Json_encode (false). "
"; The output "false"//is Json_encode transcoded, the type is string//to make a judgment to use the following example: if (Json_encode (null) = = "Null") { echo 1;} Else{ echo 2;} Output 1
Distinguishing between null and false is significant because in database interactions, such as SELECT, NULL is returned when the query result is NULL, and error returns false.
distinguishes between null and false in order to better support transactions
thinkphp Query Method Database interaction error Judgment:
$model =new model (); er = "select * from ASD where seatnm=1"; $res = $model->query (er); if (Json_encode ($res)! = " False "&& $res [0] ==null) { //result set is empty echo 123;} else if (Json_encode ($res) = = "false") { //Query error echo 789;} else{ //return non-empty result set echo 456;}
PS: I use tp3.1, do not know 3.2 is not a better judgment mechanism appears