零和NULL [英] Zero and NULL
问题描述
我有以下开关声明:
开关($ record-> sub_page){
case -1:
$ this-> page = 6;
$ error_message =''< center>您似乎已经完成了
表格。< / center> '';
休息;
案例0:
$ this-> page = 5;
ff_query (" UPDATE #__ gateway_form_1 SET`sub_page` = -1 WHERE
userid = $ my-> id和`expiry_date` =''$ expiry_date''");
休息;
默认:
做其他事情
}
$ record-> sub_page可以为NULL。如果它是NULL,那么0
的情况似乎开始了。我真的需要在
$ record-> sub_page为NULL或+ ve值时发生默认操作。
但是如果我这样做:
开关($ record-> sub_page){
case -1:
$ this-> page = 6;
休息;
case NULL:
做其他事情;
休息;
案例0:
$ this-> page = 5;
break;
默认:
做某事否则;
}
然后交换机设法告诉NULL和零之间的区别。
php将NULL视为0是否正确?
有人能建议一个好的修复吗?
TIA
问候
Paul
I have the following switch statement:
switch ($record->sub_page) {
case -1:
$this->page = 6;
$error_message = ''<center>You appear to have already completed the
form.</center>'';
break;
case 0:
$this->page = 5;
ff_query("UPDATE #__gateway_form_1 SET `sub_page`=-1 WHERE
userid=$my->id and `expiry_date` = ''$expiry_date''");
break;
default:
do something else
}
The value of $record->sub_page can be NULL. If it is NULL, the case for 0
seems to fire. I really need the default action to happen when
$record->sub_page is NULL or a +ve value.
However if I do:
switch ($record->sub_page) {
case -1:
$this->page = 6;
break;
case NULL:
do something else;
break;
case 0:
$this->page = 5;
break;
default:
do something else;
}
then the switch manages to tell the difference between a NULL and a zero.
Is it correct that php treats NULL as 0?
Can anyone suggest a good fix?
TIA
Regards
Paul
推荐答案
record-> sub_page){
case -1:
record->sub_page) {
case -1:
this-> page = 6;
this->page = 6;
error_message =''< center>您似乎已经完成
表格。< / cent呃>'';
休息;
案例0:
error_message = ''<center>You appear to have already completed the
form.</center>'';
break;
case 0:
这篇关于零和NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!