【php开源代码栏目提醒】:网学会员--在 php开源代码编辑为广大网友搜集整理了:ArrayList.class.php绩等信息,祝愿广大网友取得需要的信息,参考学习。
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* ArrayList瀹炵幇绫?
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class ArrayList extends Base implements IteratorAggregate
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 闆嗗悎鍏冪礌
+----------------------------------------------------------
* @var array
* @access protected
+----------------------------------------------------------
*/
protected $_elements = array();
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $elements 鍒濆鍖栨暟缁勫厓绱?
+----------------------------------------------------------
*/
public function __construct($elements = array())
{
if (!empty($elements)) {
$this->_elements = $elements;
}
}
/**
+----------------------------------------------------------
* 鑻ヨ鑾峰緱杩唬鍥犲瓙锛岄氳繃getIterator鏂规硶瀹炵幇
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return ArrayObject
+----------------------------------------------------------
*/
public function getIterator()
{
return new ArrayObject($this->_elements);
}
/**
+----------------------------------------------------------
* 澧炲姞鍏冪礌
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param mixed $element 瑕佹坊鍔犵殑鍏冪礌
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function add($element)
{
return (array_push($this->_elements, $element)) ? true : false;
}
//
public function unshift($element)
{
return (array_unshift($this->_elements,$element))?true : false;
}
//
public function pop()
{
return array_pop($this->_elements);
}
/**
+----------------------------------------------------------
* 澧炲姞鍏冪礌鍒楄〃
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param ArrayList $list 鍏冪礌鍒楄〃
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function addAll($list)
{
$before = $this->size();
foreach( $list as $element) {
$this->add($element);
}
$after = $this->size();
return ($before < $after);
}
/**
+----------------------------------------------------------
* 娓呴櫎鎵鏈夊厓绱?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function clear()
{
$this->_elements = array();
}
/**
+----------------------------------------------------------
* 鏄惁鍖呭惈鏌愪釜鍏冪礌
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param mixed $element 鏌ユ壘鍏冪礌
+-------