我相信在某些情况下,这会$item[2]返回null或任何其他不可数的值。从PHP 7开始,您将无法计算未实现可数的对象。所以你需要先检查它是否是一个数组:if(is_countable($item[2])){ // you can also use is_array($item[2]) if(count($item[2]) > 0){ //rest of your code }}另一种方法(虽然不是首选)是将您的对象传递给ArrayIterator. 这将使它可迭代:$item_2 = new ArrayIterator($item[2]);if(count($item_2) > 0){ //rest of your code}