<?php
/*
接口 Countable 能够使用count(mixed $var) 来计算对象的数量
*/
class MyCount implements Countable {
protected $counts = 2;
public function count(){
return $this->counts;
}
}
print count(new MyCount());//the result is :2
//同时数组也实现该接口
<?php
/*
接口 Countable 能够使用count(mixed $var) 来计算对象的数量
*/
class MyCount implements Countable {
protected $counts = 2;
public function count(){
return $this->counts;
}
}
print count(new MyCount());//the result is :2
//同时数组也实现该接口
转载于:https://my.oschina.net/20130614/blog/158796