PHP函数参考之接口 Countable

<?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)