⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iterator_034.phpt

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 PHPT
字号:
--TEST--SPL: RecursiveIteratorIterator and break deep--SKIPIF--<?php if (!extension_loaded("spl")) print "skip"; ?>--FILE--<?phpclass MyRecursiveArrayIterator extends RecursiveArrayIterator{	function valid()	{		if (!parent::valid())		{			echo __METHOD__ . "() = false\n";			return false;		}		else		{			return true;		}	}	function getChildren()	{		echo __METHOD__ . "()\n";		return parent::getChildren();	}		function rewind()	{		echo __METHOD__ . "()\n";		parent::rewind();	}}class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator{	private $max_depth;	private $over = 0;	function __construct($it, $max_depth)	{		$this->max_depth = $max_depth;		parent::__construct($it);	}	function rewind()	{		echo __METHOD__ . "() - BEGIN\n";		parent::rewind();		echo __METHOD__ . "() - DONE\n";	}	function valid()	{		echo __METHOD__ . "()\n";		return parent::valid();	}	function current()	{		echo __METHOD__ . "()\n";		return parent::current();	}	function key()	{		echo __METHOD__ . "()\n";		return parent::key();	}	function next()	{		echo __METHOD__ . "()\n";		parent::next();	}	function callHasChildren()	{		$has = parent::callHasChildren();		$res = $this->getDepth() < $this->max_depth && $has;		echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n";		return $res;	}	function beginChildren()	{		echo __METHOD__ . "(".$this->getDepth().")\n";		parent::beginChildren();	}	function endChildren()	{		echo __METHOD__ . "(".$this->getDepth().")\n";		parent::endChildren();	}}$p = 0;$it = new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2);foreach($it as $k=>$v){	if (is_array($v)) $v = join('',$v);	echo "$k=>$v\n";	if ($p++ == 5)	{		echo "===BREAK===\n";		break;	}}echo "===FOREND===\n";$it->rewind();echo "===CHECK===\n";var_dump($it->valid());var_dump($it->current() == "a");?>===DONE===<?php exit(0); ?>--EXPECT--RecursiveArrayIteratorIterator::rewind() - BEGINMyRecursiveArrayIterator::rewind()RecursiveArrayIteratorIterator::callHasChildren(0) = no/noRecursiveArrayIteratorIterator::rewind() - DONERecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()0=>aRecursiveArrayIteratorIterator::next()RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yesMyRecursiveArrayIterator::getChildren()MyRecursiveArrayIterator::rewind()RecursiveArrayIteratorIterator::beginChildren(1)RecursiveArrayIteratorIterator::callHasChildren(1) = no/noRecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()0=>baRecursiveArrayIteratorIterator::next()RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yesMyRecursiveArrayIterator::getChildren()MyRecursiveArrayIterator::rewind()RecursiveArrayIteratorIterator::beginChildren(2)RecursiveArrayIteratorIterator::callHasChildren(2) = no/noRecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()0=>bbaRecursiveArrayIteratorIterator::next()RecursiveArrayIteratorIterator::callHasChildren(2) = no/noRecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()1=>bbbRecursiveArrayIteratorIterator::next()MyRecursiveArrayIterator::valid() = falseRecursiveArrayIteratorIterator::endChildren(2)RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yesMyRecursiveArrayIterator::getChildren()MyRecursiveArrayIterator::rewind()RecursiveArrayIteratorIterator::beginChildren(2)RecursiveArrayIteratorIterator::callHasChildren(2) = no/yesRecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()0=>bcaaRecursiveArrayIteratorIterator::next()RecursiveArrayIteratorIterator::callHasChildren(2) = no/yesRecursiveArrayIteratorIterator::valid()RecursiveArrayIteratorIterator::current()RecursiveArrayIteratorIterator::key()1=>bcba===BREAK======FOREND===RecursiveArrayIteratorIterator::rewind() - BEGINRecursiveArrayIteratorIterator::endChildren(1)RecursiveArrayIteratorIterator::endChildren(0)MyRecursiveArrayIterator::rewind()RecursiveArrayIteratorIterator::callHasChildren(0) = no/noRecursiveArrayIteratorIterator::rewind() - DONE===CHECK===RecursiveArrayIteratorIterator::valid()bool(true)RecursiveArrayIteratorIterator::current()bool(true)===DONE===

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -