简体   繁体   English

为什么“ if($ _ SESSION ['count']> = 3””给我错误?

[英]Why does “if($_SESSION['count'] >= 3” giving me error?

This php line 这条PHP线

<?php if($_SESSION['count'] >= 3)?> 

of code gives me the following error message 的代码给我以下错误消息

Notice: Undefined index: count in C:\\xampp\\htdocs\\vb\\Step4.php on line 451 Number of Room/s 注意:未定义的索引:在第451行的C:\\ xampp \\ htdocs \\ vb \\ Step4.php中计数

You need to check for the existence of the count index before trying to use it - so: 您需要在使用count索引之前检查其是否存在-因此:

<?php
    if( !empty( $_SESSION['count'] ) && intval( $_SESSION['count'] ) >= 3 ){/* do something */}
?>

You could use isset to test that the index has been defined but empty does that and also checks that whatever value is held does is not empty and not equate to false. 您可以使用isset来测试是否已定义了索引,但是可以使用empty进行检查,还可以检查所保存的值是否不为空且不等于false。

Session with name 'count' is not set. 未设置名称为“ count”的会话。 ie The array $_SESSION does not any key with name 'count'. 即数组$ _SESSION没有任何名称为'count'的键。

Also, it is a NOTICE ( information ) not an ERROR. 另外,它是一个NOTICE(信息)而不是一个ERROR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM