<?php //CountableClass.php
class CountMe implements Countable
{
protected $_myCount =3;
public function count(){
return $this->_myCount;
}
}
$obj = new CountMe();
echo $obj->count()."<br />";
echo count($obj)."<Br />";
?>
class CountMe implements Countable
{
protected $_myCount =3;
public function count(){
return $this->_myCount;
}
}
$obj = new CountMe();
echo $obj->count()."<br />";
echo count($obj)."<Br />";
?>
2018-04-09
没有实现 Countable 接口的类的对象被用于 count() 函数总是返回 1,这与类的成员数量没有任何关系。
http://php.net/manual/zh/function.count.php
http://php.net/manual/zh/function.count.php
2018-02-10
http://blog.csdn.net/everything1209/article/details/51475281#%E8%87%AA%E5%AE%9A%E4%B9%89autoload%E5%87%BD%E6%95%B0%E8%A3%85%E8%BD%BD%E7%B1%BB
2018-01-26
<?php
$array = array("apple", "banana", "cherry", "damson", "elderberry");
$iterator = new ArrayIterator($array);
$iterator->seek(3);
echo $iterator->current();
?>
The above example will output something similar to:
damson
$array = array("apple", "banana", "cherry", "damson", "elderberry");
$iterator = new ArrayIterator($array);
$iterator->seek(3);
echo $iterator->current();
?>
The above example will output something similar to:
damson
2018-01-25
http://www.phptuku.com/php/basic/284.html 这个注释“Countable 继承了该接口的类可以直接调用count()得到元素个数”应该错了吧,PHP手册上的解释也一样 。应该改为“实现Countable 接口的类count($obj)相当于调用类中的count()方法。没有实现Countable 接口的类,调用count($obj)得到类的元素个数
2018-01-25