Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 变量是数组但不是可数的?_Php_Codeigniter_Count_Countable - Fatal编程技术网

Php 变量是数组但不是可数的?

Php 变量是数组但不是可数的?,php,codeigniter,count,countable,Php,Codeigniter,Count,Countable,我正在将我们的Codeigniter(v.3.1.11)站点从PHP5.6升级到PHP7.2(目前在我的Mac上的localhost上运行)。慢慢地,我找到了count()用法的所有实例并进行了更正。据我所知,数组是可数的,但我似乎无法在数据库调用后计算Codeigniter的result_array()函数返回的数组数 我的控制器的以下部分 $reviews = $this->reviews_model->review_details($productname);

我正在将我们的Codeigniter(v.3.1.11)站点从PHP5.6升级到PHP7.2(目前在我的Mac上的localhost上运行)。慢慢地,我找到了count()用法的所有实例并进行了更正。据我所知,数组是可数的,但我似乎无法在数据库调用后计算Codeigniter的result_array()函数返回的数组数

我的控制器的以下部分

    $reviews = $this->reviews_model->review_details($productname);
    echo "Variable is type: ".gettype($reviews);
    if (count($reviews >=1)) {
        $myreview=$reviews[0];
    } else {
        $myreview=0;
    }
    return $myreview;
在我的模型中调用此函数(请注意,我只是回显变量类型以确保!)

即使变量是数组

Variable is type: array
到现在为止,我仍然收到了非常熟悉的警告信息:

Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: controllers/Software.php
Line Number: 1005

Backtrace:

File: /Users/juner/Sites/html/application/controllers/Software.php
Line: 1005
Function: _error_handler
File: /Users/juner/Sites/html/application/controllers/Software.php
Line: 75
Function: _get_my_review

File: /Users/juner/Sites/html/index.php
Line: 324
Function: require_once
是否存在不可计数的数组类型?任何建议/想法都会非常有用

此部分不正确(打字错误):

您正在将布尔值传递给count函数<代码>计数($reviews>=1)变为
计数(true)
;这就是你得到警告的原因


if(count($reviews>=1)){
应该是
if(count($reviews)>=1){
天哪!真是个愚蠢的错误。是的,这个修正允许它被计数。但这确实让我想知道在PHP5.6中,5.6是如何工作的!在PHP5.6中,
count(true)
为您提供
1
由于。因此在您的情况下,它返回1并允许循环继续。
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: controllers/Software.php
Line Number: 1005

Backtrace:

File: /Users/juner/Sites/html/application/controllers/Software.php
Line: 1005
Function: _error_handler
File: /Users/juner/Sites/html/application/controllers/Software.php
Line: 75
Function: _get_my_review

File: /Users/juner/Sites/html/index.php
Line: 324
Function: require_once
if (count($reviews >=1)) {
    $myreview=$reviews[0];
} else {
    $myreview=0;
}