本文整理汇总了PHP中AppendIterator::getArrayIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP AppendIterator::getArrayIterator方法的具体用法?PHP AppendIterator::getArrayIterator怎么用?PHP AppendIterator::getArrayIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppendIterator
的用法示例。
在下文中一共展示了AppendIterator::getArrayIterator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: concat
/**
* Concatenates one or more foreach-able object into an Iterator.
* If no objects provided, returns an empty iterator.
* \AppendIterators provided will be deep copied.
* This means changes to \AppendIterator parameters will not be reflected
* in the resulting \Iterator.
* @return \Iterator
*/
public static function concat()
{
$argCount = \func_num_args();
if ($argCount === 0) {
return new \EmptyIterator();
} elseif ($argCount === 1) {
return Iterators::ensureIsIterator(\func_get_args()[0]);
} else {
$retval = new \AppendIterator();
//Workaround for AppendIterator bugs
//https://bugs.php.net/bug.php?id=49104
//https://bugs.php.net/bug.php?id=62212
$retval->append(new \ArrayIterator([0]));
unset($retval->getArrayIterator()[0]);
$recursiveAttach = static function ($iter) use(&$recursiveAttach, $retval) {
foreach ($iter as $concatedIter) {
if ($concatedIter instanceof \AppendIterator) {
$recursiveAttach($concatedIter->getArrayIterator());
} elseif ($concatedIter instanceof \EmptyIterator) {
//Do not add it.
} else {
$retval->append($concatedIter);
}
}
return $retval;
};
return (new \Yasca\Core\FunctionPipe())->wrap(\func_get_args())->pipe([Iterators::_class, 'ensureIsIterator'])->pipe([Iterators::_class, 'select'], [Iterators::_class, 'ensureIsIterator'])->pipe($recursiveAttach)->unwrap();
}
}
示例2: test_error_handler
<?php
function test_error_handler($errno, $msg, $filename, $linenum)
{
echo "Error {$msg} in {$filename} on line {$linenum}\n";
return true;
}
set_error_handler('test_error_handler');
$it = new AppendIterator();
try {
$it->append(array());
} catch (Error $e) {
test_error_handler($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
}
$it->append(new ArrayIterator(array(1)));
$it->append(new ArrayIterator(array(21, 22)));
var_dump($it->getArrayIterator());
$it->append(new ArrayIterator(array(31, 32, 33)));
var_dump($it->getArrayIterator());
$idx = 0;
foreach ($it as $k => $v) {
echo '===' . $idx++ . "===\n";
var_dump($it->getIteratorIndex());
var_dump($k);
var_dump($v);
}
?>
===DONE===