Spl/iterators-Phpdoc专题
迭代器
目录
- AppendIterator — The
AppendIterator class
- AppendIterator::append — Appends an iterator
- AppendIterator::__construct — Constructs an AppendIterator
- AppendIterator::current — Gets the current value
- AppendIterator::getArrayIterator — Gets the ArrayIterator
- AppendIterator::getInnerIterator — Gets the inner iterator
- AppendIterator::getIteratorIndex — Gets an index of iterators
- AppendIterator::key — Gets the current key
- AppendIterator::next — Moves to the next element
- AppendIterator::rewind — Rewinds the Iterator
- AppendIterator::valid — Checks validity of the current element
- ArrayIterator — ArrayIterator
类
- ArrayIterator::append — Append an element
- ArrayIterator::asort — Sort array by values
- ArrayIterator::__construct — Construct an ArrayIterator
- ArrayIterator::count — Count elements
- ArrayIterator::current — Return current array entry
- ArrayIterator::getArrayCopy — Get array copy
- ArrayIterator::getFlags — Get behavior flags
- ArrayIterator::key — Return current array key
- ArrayIterator::ksort — Sort array by keys
- ArrayIterator::natcasesort — Sort an array naturally, case insensitive
- ArrayIterator::natsort — Sort an array naturally
- ArrayIterator::next — Move to next entry
- ArrayIterator::offsetExists — Check if offset exists
- ArrayIterator::offsetGet — Get value for an offset
- ArrayIterator::offsetSet — Set value for an offset
- ArrayIterator::offsetUnset — Unset value for an offset
- ArrayIterator::rewind — Rewind array back to the start
- ArrayIterator::seek — Seek to position
- ArrayIterator::serialize — Serialize
- ArrayIterator::setFlags — Set behaviour flags
- ArrayIterator::uasort — Sort with a user-defined comparison function and maintain index association
- ArrayIterator::uksort — Sort by keys using a user-defined comparison function
- ArrayIterator::unserialize — Unserialize
- ArrayIterator::valid — Check whether array contains more entries
- CachingIterator — The
CachingIterator class
- CachingIterator::__construct — Construct a new CachingIterator object for the iterator
- CachingIterator::count — The number of elements in the iterator
- CachingIterator::current — Return the current element
- CachingIterator::getCache — Retrieve the contents of the cache
- CachingIterator::getFlags — Get flags used
- CachingIterator::getInnerIterator — Returns the inner iterator
- CachingIterator::hasNext — Check whether the inner iterator has a valid next element
- CachingIterator::key — Return the key for the current element
- CachingIterator::next — Move the iterator forward
- CachingIterator::offsetExists — The offsetExists purpose
- CachingIterator::offsetGet — The offsetGet purpose
- CachingIterator::offsetSet — The offsetSet purpose
- CachingIterator::offsetUnset — The offsetUnset purpose
- CachingIterator::rewind — Rewind the iterator
- CachingIterator::setFlags — The setFlags purpose
- CachingIterator::__toString — Return the string representation of the current element
- CachingIterator::valid — Check whether the current element is valid
- CallbackFilterIterator
— The CallbackFilterIterator class
- CallbackFilterIterator::accept — Calls the callback with the current value, the current key and the inner iterator as arguments
- CallbackFilterIterator::__construct — Create a filtered iterator from another iterator
- DirectoryIterator — The
DirectoryIterator class
- DirectoryIterator::__construct — Constructs a new directory iterator from a path
- DirectoryIterator::current — Return the current DirectoryIterator item
- DirectoryIterator::getATime — Get last access time of the current DirectoryIterator item
- DirectoryIterator::getBasename — Get base name of current DirectoryIterator item
- DirectoryIterator::getCTime — Get inode change time of the current DirectoryIterator item
- DirectoryIterator::getExtension — Gets the file extension
- DirectoryIterator::getFilename — Return file name of current DirectoryIterator item
- DirectoryIterator::getGroup — Get group for the current DirectoryIterator item
- DirectoryIterator::getInode — Get inode for the current DirectoryIterator item
- DirectoryIterator::getMTime — Get last modification time of current DirectoryIterator item
- DirectoryIterator::getOwner — Get owner of current DirectoryIterator item
- DirectoryIterator::getPath — Get path of current Iterator item without filename
- DirectoryIterator::getPathname — Return path and file name of current DirectoryIterator item
- DirectoryIterator::getPerms — Get the permissions of current DirectoryIterator item
- DirectoryIterator::getSize — Get size of current DirectoryIterator item
- DirectoryIterator::getType — Determine the type of the current DirectoryIterator item
- DirectoryIterator::isDir — Determine if current DirectoryIterator item is a directory
- DirectoryIterator::isDot — Determine if current DirectoryIterator item is '.' or '..'
- DirectoryIterator::isExecutable — Determine if current DirectoryIterator item is executable
- DirectoryIterator::isFile — Determine if current DirectoryIterator item is a regular file
- DirectoryIterator::isLink — Determine if current DirectoryIterator item is a symbolic link
- DirectoryIterator::isReadable — Determine if current DirectoryIterator item can be read
- DirectoryIterator::isWritable — Determine if current DirectoryIterator item can be written to
- DirectoryIterator::key — Return the key for the current DirectoryIterator item
- DirectoryIterator::next — Move forward to next DirectoryIterator item
- DirectoryIterator::rewind — Rewind the DirectoryIterator back to the start
- DirectoryIterator::seek — Seek to a DirectoryIterator item
- DirectoryIterator::__toString — Get file name as a string
- DirectoryIterator::valid — Check whether current DirectoryIterator position is a valid file
- EmptyIterator — The
EmptyIterator class
- EmptyIterator::current — The current() method
- EmptyIterator::key — The key() method
- EmptyIterator::next — The next() method
- EmptyIterator::rewind — The rewind() method
- EmptyIterator::valid — The valid() method
- FilesystemIterator — The
FilesystemIterator class
- FilesystemIterator::__construct — Constructs a new filesystem iterator
- FilesystemIterator::current — The current file
- FilesystemIterator::getFlags — Get the handling flags
- FilesystemIterator::key — Retrieve the key for the current file
- FilesystemIterator::next — Move to the next file
- FilesystemIterator::rewind — Rewinds back to the beginning
- FilesystemIterator::setFlags — Sets handling flags
- FilterIterator — The
FilterIterator class
- FilterIterator::accept — Check whether the current element of the iterator is acceptable
- FilterIterator::__construct — Construct a filterIterator
- FilterIterator::current — Get the current element value
- FilterIterator::getInnerIterator — Get the inner iterator
- FilterIterator::key — Get the current key
- FilterIterator::next — Move the iterator forward
- FilterIterator::rewind — Rewind the iterator
- FilterIterator::valid — Check whether the current element is valid
- GlobIterator — The GlobIterator
class
- GlobIterator::__construct — Construct a directory using glob
- GlobIterator::count — Get the number of directories and files
- InfiniteIterator — The
InfiniteIterator class
- InfiniteIterator::__construct — Constructs an InfiniteIterator
- InfiniteIterator::next — Moves the inner Iterator forward or rewinds it
- IteratorIterator — The
IteratorIterator class
- IteratorIterator::__construct — Create an iterator from anything that is traversable
- IteratorIterator::current — Get the current value
- IteratorIterator::getInnerIterator — Get the inner iterator
- IteratorIterator::key — Get the key of the current element
- IteratorIterator::next — Forward to the next element
- IteratorIterator::rewind — Rewind to the first element
- IteratorIterator::valid — Checks if the iterator is valid
- LimitIterator — The
LimitIterator class
- LimitIterator::__construct — Construct a LimitIterator
- LimitIterator::current — Get current element
- LimitIterator::getInnerIterator — Get inner iterator
- LimitIterator::getPosition — Return the current position
- LimitIterator::key — Get current key
- LimitIterator::next — Move the iterator forward
- LimitIterator::rewind — Rewind the iterator to the specified starting offset
- LimitIterator::seek — Seek to the given position
- LimitIterator::valid — Check whether the current element is valid
- MultipleIterator — The
MultipleIterator class
- MultipleIterator::attachIterator — Attaches iterator information
- MultipleIterator::__construct — Constructs a new MultipleIterator
- MultipleIterator::containsIterator — Checks if an iterator is attached
- MultipleIterator::countIterators — Gets the number of attached iterator instances
- MultipleIterator::current — Gets the registered iterator instances
- MultipleIterator::detachIterator — Detaches an iterator
- MultipleIterator::getFlags — Gets the flag information
- MultipleIterator::key — Gets the registered iterator instances
- MultipleIterator::next — Moves all attached iterator instances forward
- MultipleIterator::rewind — Rewinds all attached iterator instances
- MultipleIterator::setFlags — Sets flags
- MultipleIterator::valid — Checks the validity of sub iterators
- NoRewindIterator — The
NoRewindIterator class
- NoRewindIterator::__construct — Construct a NoRewindIterator
- NoRewindIterator::current — Get the current value
- NoRewindIterator::getInnerIterator — Get the inner iterator
- NoRewindIterator::key — Get the current key
- NoRewindIterator::next — Forward to the next element
- NoRewindIterator::rewind — Prevents the rewind operation on the inner iterator
- NoRewindIterator::valid — Validates the iterator
- ParentIterator — The
ParentIterator class
- ParentIterator::accept — Determines acceptability
- ParentIterator::__construct — Constructs a ParentIterator
- ParentIterator::getChildren — Return the inner iterator's children contained in a ParentIterator
- ParentIterator::hasChildren — Check whether the inner iterator's current element has children
- ParentIterator::next — Move the iterator forward
- ParentIterator::rewind — Rewind the iterator
- RecursiveArrayIterator
— The RecursiveArrayIterator class
- RecursiveArrayIterator::getChildren — Returns an iterator for the current entry if it is an array or an object
- RecursiveArrayIterator::hasChildren — Returns whether current entry is an array or an object
- RecursiveCachingIterator
— The RecursiveCachingIterator class
- RecursiveCachingIterator::__construct — Construct
- RecursiveCachingIterator::getChildren — Return the inner iterator's children as a RecursiveCachingIterator
- RecursiveCachingIterator::hasChildren — Check whether the current element of the inner iterator has children
- RecursiveCallbackFilterIterator
— The RecursiveCallbackFilterIterator class
- RecursiveCallbackFilterIterator::__construct — Create a RecursiveCallbackFilterIterator from a RecursiveIterator
- RecursiveCallbackFilterIterator::getChildren — Return the inner iterator's children contained in a RecursiveCallbackFilterIterator
- RecursiveCallbackFilterIterator::hasChildren — Check whether the inner iterator's current element has children
- RecursiveDirectoryIterator
— The RecursiveDirectoryIterator class
- RecursiveDirectoryIterator::__construct — Constructs a RecursiveDirectoryIterator
- RecursiveDirectoryIterator::getChildren — Returns an iterator for the current entry if it is a directory
- RecursiveDirectoryIterator::getSubPath — Get sub path
- RecursiveDirectoryIterator::getSubPathname — Get sub path and name
- RecursiveDirectoryIterator::hasChildren — Returns whether current entry is a directory and not '.' or '..'
- RecursiveDirectoryIterator::key — Return path and filename of current dir entry
- RecursiveDirectoryIterator::next — Move to next entry
- RecursiveDirectoryIterator::rewind — Rewind dir back to the start
- RecursiveFilterIterator
— The RecursiveFilterIterator class
- RecursiveFilterIterator::__construct — Create a RecursiveFilterIterator from a RecursiveIterator
- RecursiveFilterIterator::getChildren — Return the inner iterator's children contained in a RecursiveFilterIterator
- RecursiveFilterIterator::hasChildren — Check whether the inner iterator's current element has children
- RecursiveIteratorIterator
— The RecursiveIteratorIterator class
- RecursiveIteratorIterator::beginChildren — Begin children
- RecursiveIteratorIterator::beginIteration — Begin Iteration
- RecursiveIteratorIterator::callGetChildren — Get children
- RecursiveIteratorIterator::callHasChildren — Has children
- RecursiveIteratorIterator::__construct — Construct a RecursiveIteratorIterator
- RecursiveIteratorIterator::current — Access the current element value
- RecursiveIteratorIterator::endChildren — End children
- RecursiveIteratorIterator::endIteration — End Iteration
- RecursiveIteratorIterator::getDepth — Get the current depth of the recursive iteration
- RecursiveIteratorIterator::getInnerIterator — Get inner iterator
- RecursiveIteratorIterator::getMaxDepth — Get max depth
- RecursiveIteratorIterator::getSubIterator — The current active sub iterator
- RecursiveIteratorIterator::key — Access the current key
- RecursiveIteratorIterator::next — Move forward to the next element
- RecursiveIteratorIterator::nextElement — Next element
- RecursiveIteratorIterator::rewind — Rewind the iterator to the first element of the top level inner iterator
- RecursiveIteratorIterator::setMaxDepth — Set max depth
- RecursiveIteratorIterator::valid — Check whether the current position is valid
- RecursiveRegexIterator
— The RecursiveRegexIterator class
- RecursiveRegexIterator::__construct — Creates a new RecursiveRegexIterator
- RecursiveRegexIterator::getChildren — Returns an iterator for the current entry
- RecursiveRegexIterator::hasChildren — Returns whether an iterator can be obtained for the current entry
- RecursiveTreeIterator —
The RecursiveTreeIterator class
- RecursiveTreeIterator::beginChildren — Begin children
- RecursiveTreeIterator::beginIteration — Begin iteration
- RecursiveTreeIterator::callGetChildren — Get children
- RecursiveTreeIterator::callHasChildren — Has children
- RecursiveTreeIterator::__construct — Construct a RecursiveTreeIterator
- RecursiveTreeIterator::current — Get current element
- RecursiveTreeIterator::endChildren — End children
- RecursiveTreeIterator::endIteration — End iteration
- RecursiveTreeIterator::getEntry — Get current entry
- RecursiveTreeIterator::getPostfix — Get the postfix
- RecursiveTreeIterator::getPrefix — Get the prefix
- RecursiveTreeIterator::key — Get the key of the current element
- RecursiveTreeIterator::next — Move to next element
- RecursiveTreeIterator::nextElement — Next element
- RecursiveTreeIterator::rewind — Rewind iterator
- RecursiveTreeIterator::setPostfix — Set postfix
- RecursiveTreeIterator::setPrefixPart — Set a part of the prefix
- RecursiveTreeIterator::valid — Check validity
- RegexIterator — The
RegexIterator class
- RegexIterator::accept — Get accept status
- RegexIterator::__construct — Create a new RegexIterator
- RegexIterator::getFlags — Get flags
- RegexIterator::getMode — Returns operation mode
- RegexIterator::getPregFlags — Returns the regular expression flags
- RegexIterator::getRegex — Returns current regular expression
- RegexIterator::setFlags — Sets the flags
- RegexIterator::setMode — Sets the operation mode
- RegexIterator::setPregFlags — Sets the regular expression flags
SPL 提供一系列迭代器以遍历不同的对象。
SPL Iterators Class Tree
- <span
class="classname">ArrayIterator
- <span class="classname">RecursiveArrayIterator
- <span class="classname">EmptyIterator
- <span
class="classname">IteratorIterator
- <span class="classname">AppendIterator
- <span
class="classname">CachingIterator
- <span class="classname">RecursiveCachingIterator
- <span
class="classname">FilterIterator
- <span
class="classname">CallbackFilterIterator
- <span class="classname">RecursiveCallbackFilterIterator
- <span
class="classname">RecursiveFilterIterator
- <span class="classname">ParentIterator
- <span
class="classname">RegexIterator
- <span class="classname">RecursiveRegexIterator
- <span
class="classname">CallbackFilterIterator
- <span class="classname">InfiniteIterator
- <span class="classname">LimitIterator
- <span class="classname">NoRewindIterator
- <span class="classname">MultipleIterator
- <span
class="classname">RecursiveIteratorIterator
- <span class="classname">RecursiveTreeIterator
- <span
class="classname">DirectoryIterator (extends <span
class="classname">SplFileInfo)
- <span
class="classname">FilesystemIterator
- <span class="classname">GlobIterator
- <span class="classname">RecursiveDirectoryIterator
- <span
class="classname">FilesystemIterator
简介
这个迭代器能陆续遍历几个迭代器
类摘要
AppendIterator
class AppendIterator <span class="ooclass"> extends IteratorIterator implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span class="methodname">__construct ( <span class="methodparam">void )
public void
append ( <span
class="type">Iterator $iterator )
public mixed current ( <span class="methodparam">void )
public <span class="type">ArrayIterator <span class="methodname">getArrayIterator ( <span class="methodparam">void )
public Iterator getInnerIterator ( <span class="methodparam">void )
public int <span class="methodname">getIteratorIndex ( <span class="methodparam">void )
public scalar key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
/* 继承的方法 */
public <span
class="methodname">IteratorIterator::__construct ( <span
class="methodparam">Traversable
$iterator )
public mixed IteratorIterator::current ( <span class="methodparam">void )
public <span class="type">Traversable <span class="methodname">IteratorIterator::getInnerIterator ( <span class="methodparam">void )
public mixed IteratorIterator::key ( <span class="methodparam">void )
public void IteratorIterator::next ( <span class="methodparam">void )
public void IteratorIterator::rewind ( <span class="methodparam">void )
public bool IteratorIterator::valid ( <span class="methodparam">void )
}
AppendIterator::append
Appends an iterator
说明
public void
AppendIterator::append ( <span
class="methodparam">Iterator
$iterator )
Appends an iterator.
参数
iterator
The iterator to append.
返回值
没有返回值。
范例
示例 #1 AppendIterator::append example
<?php
$array_a = new ArrayIterator(array('a', 'b', 'c'));
$array_b = new ArrayIterator(array('d', 'e', 'f'));
$iterator = new AppendIterator;
$iterator->append($array_a);
$iterator->append($array_b);
foreach ($iterator as $current) {
echo $current;
}
?>
以上例程会输出:
abcdef
参见
- AppendIterator::__construct
AppendIterator::__construct
Constructs an AppendIterator
说明
public <span class="methodname">AppendIterator::__construct ( <span class="methodparam">void )
Constructs an AppendIterator.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 Iterating AppendIterator with foreach
<?php
$pizzas = new ArrayIterator(array('Margarita', 'Siciliana', 'Hawaii'));
$toppings = new ArrayIterator(array('Cheese', 'Anchovies', 'Olives', 'Pineapple', 'Ham'));
$appendIterator = new AppendIterator;
$appendIterator->append($pizzas);
$appendIterator->append($toppings);
foreach ($appendIterator as $key => $item) {
echo $key . ' => ' . $item . PHP_EOL;
}
?>
以上例程会输出:
0 => Margarita
1 => Siciliana
2 => Hawaii
0 => Cheese
1 => Anchovies
2 => Olives
3 => Pineapple
4 => Ham
示例 #2 Iterating AppendIterator with the AppendIterator API
<?php
$pizzas = new ArrayIterator(array('Margarita', 'Siciliana', 'Hawaii'));
$toppings = new ArrayIterator(array('Cheese', 'Anchovies', 'Olives', 'Pineapple', 'Ham'));
$appendIterator = new AppendIterator;
$appendIterator->append($pizzas);
$appendIterator->append($toppings);
while ($appendIterator->valid()) {
printf(
'%s => %s => %s%s',
$appendIterator->getIteratorIndex(),
$appendIterator->key(),
$appendIterator->current(),
PHP_EOL
);
$appendIterator->next();
}
?>
以上例程会输出:
0 => 0 => Margarita
0 => 1 => Siciliana
0 => 2 => Hawaii
1 => 0 => Cheese
1 => 1 => Anchovies
1 => 2 => Olives
1 => 3 => Pineapple
1 => 4 => Ham
注释
Caution
When using iterator_to_array to copy the
values of the AppendIterator into an array, you have to set the optional
use_key argument to false. When use_key is not false any
keys reoccuring in inner iterators will get overwritten in the returned
array. There is no way to preserve the original keys.
参见
- AppendIterator::append
AppendIterator::current
Gets the current value
说明
public mixed AppendIterator::current ( <span class="methodparam">void )
Gets the current value.
参数
此函数没有参数。
返回值
The current value if it is valid or null otherwise.
参见
- Iterator::current
- AppendIterator::key
- AppendIterator::valid
- AppendIterator::next
- AppendIterator::rewind
AppendIterator::getArrayIterator
Gets the ArrayIterator
说明
public <span class="type">ArrayIterator <span class="methodname">AppendIterator::getArrayIterator ( <span class="methodparam">void )
This method gets the ArrayIterator that is used to store the iterators added with <span class="methodname">AppendIterator::append.
参数
此函数没有参数。
返回值
Returns an ArrayIterator containing the appended iterators.
参见
- AppendIterator::getInnerIterator
AppendIterator::getInnerIterator
Gets the inner iterator
说明
public Iterator AppendIterator::getInnerIterator ( <span class="methodparam">void )
This method returns the current inner iterator.
参数
此函数没有参数。
返回值
The current inner iterator, or null if there is not one.
范例
示例 #1 <span class="methodname">AppendIterator::getInnerIterator example
<?php
$array_a = new ArrayIterator(array('a' => 'aardwolf', 'b' => 'bear', 'c' => 'capybara'));
$array_b = new RegexIterator($array_a, '/^[ac]/');
$iterator = new AppendIterator;
$iterator->append($array_a);
$iterator->append($array_b);
foreach ($iterator as $current) {
$inner = $iterator->getInnerIterator();
if ($inner instanceOf RegexIterator) {
echo 'Filtered: ';
} else {
echo 'Original: ';
}
echo $current . PHP_EOL;
}
?>
以上例程会输出:
Original: aardwolf
Original: bear
Original: capybara
Filtered: aardwolf
Filtered: capybara
参见
- AppendIterator::getIteratorIndex
AppendIterator::getIteratorIndex
Gets an index of iterators
说明
public int <span class="methodname">AppendIterator::getIteratorIndex ( <span class="methodparam">void )
Gets the index of the current inner iterator.
参数
此函数没有参数。
返回值
Returns an int, which is the zero-based index of the current inner iterator.
范例
示例 #1 <span class="methodname">AppendIterator.getIteratorIndex basic example
<?php
$array_a = new ArrayIterator(array('a' => 'aardwolf', 'b' => 'bear', 'c' => 'capybara'));
$array_b = new ArrayIterator(array('apple', 'orange', 'lemon'));
$iterator = new AppendIterator;
$iterator->append($array_a);
$iterator->append($array_b);
foreach ($iterator as $key => $current) {
echo $iterator->getIteratorIndex() . ' ' . $key . ' ' . $current . PHP_EOL;
}
?>
以上例程会输出:
0 a aardwolf
0 b bear
0 c capybara
1 0 apple
1 1 orange
1 2 lemon
参见
- AppendIterator::getInnerIterator
- AppendIterator::getArrayIterator
AppendIterator::key
Gets the current key
说明
public scalar AppendIterator::key ( <span class="methodparam">void )
Get the current key.
参数
此函数没有参数。
返回值
The current key if it is valid or null otherwise.
范例
示例 #1 AppendIterator::key basic example
<?php
$array_a = new ArrayIterator(array('a' => 'aardwolf', 'b' => 'bear', 'c' => 'capybara'));
$array_b = new ArrayIterator(array('apple', 'orange', 'lemon'));
$iterator = new AppendIterator;
$iterator->append($array_a);
$iterator->append($array_b);
// Manual iteration
$iterator->rewind();
while ($iterator->valid()) {
echo $iterator->key() . ' ' . $iterator->current() . PHP_EOL;
$iterator->next();
}
echo PHP_EOL;
// With foreach
foreach ($iterator as $key => $current) {
echo $key . ' ' . $current . PHP_EOL;
}
?>
以上例程会输出:
a aardwolf
b bear
c capybara
0 apple
1 orange
2 lemon
a aardwolf
b bear
c capybara
0 apple
1 orange
2 lemon
参见
- Iterator::key
- AppendIterator::current
- AppendIterator::valid
- AppendIterator::next
- AppendIterator::rewind
AppendIterator::next
Moves to the next element
说明
public void AppendIterator::next ( <span class="methodparam">void )
Moves to the next element. If this means to another Iterator then it rewinds that Iterator.
参数
此函数没有参数。
返回值
没有返回值。
参见
- Iterator::next
- AppendIterator::current
- AppendIterator::key
- AppendIterator::valid
- AppendIterator::rewind
AppendIterator::rewind
Rewinds the Iterator
说明
public void AppendIterator::rewind ( <span class="methodparam">void )
Rewind to the first element of the first inner Iterator.
参数
此函数没有参数。
返回值
没有返回值。
参见
- Iterator::rewind
- AppendIterator::current
- AppendIterator::key
- AppendIterator::next
- AppendIterator::valid
AppendIterator::valid
Checks validity of the current element
说明
public bool AppendIterator::valid ( <span class="methodparam">void )
Checks validity of the current element.
参数
此函数没有参数。
返回值
Returns true if the current iteration is valid, false
otherwise.
参见
- AppendIterator::current
- AppendIterator::key
- AppendIterator::next
- AppendIterator::rewind
简介
这个迭代器允许在遍历数组和对象时删除和更新值与键。
当你想多次遍历相同数组时你需要实例化 ArrayObject,然后让这个实例创建一个 ArrayIteratror 实例。 当你想遍历相同数组时多次你需要实例 ArrayObject 并且让这个实例创建一个 ArrayIteratror 实例,然后使用foreach 或者 手动调用 getIterator() 方法。
类摘要
ArrayIterator
class ArrayIterator <span class="oointerface">implements <span class="interfacename">ArrayAccess <span class="oointerface">, <span class="interfacename">SeekableIterator <span class="oointerface">, Countable , <span class="interfacename">Serializable {
/* 常量 */
const integer
STD_PROP_LIST = 1 ;
const integer
ARRAY_AS_PROPS = 2 ;
/* 方法 */
public void
append ( <span
class="type">mixed $value )
public void asort ( <span class="methodparam">void )
public <span
class="methodname">__construct ([ <span
class="methodparam">mixed $array<span
class="initializer"> = array() [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
public int <span class="methodname">count ( void )
public mixed current ( <span class="methodparam">void )
public array getArrayCopy ( <span class="methodparam">void )
public int <span class="methodname">getFlags ( <span class="methodparam">void )
public mixed key ( <span class="methodparam">void )
public void ksort ( <span class="methodparam">void )
public void natcasesort ( <span class="methodparam">void )
public void natsort ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public bool
offsetExists ( <span
class="methodparam">mixed $index )
public mixed
offsetGet ( <span
class="methodparam">mixed $index )
public void
offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
public void
offsetUnset ( <span
class="methodparam">mixed $index )
public void rewind ( <span class="methodparam">void )
public void
seek ( <span
class="type">int $position )
public string serialize ( <span class="methodparam">void )
public void
setFlags ( <span
class="methodparam">string $flags )
public void
uasort ( <span
class="type">callable $cmp_function )
public void
uksort ( <span
class="type">callable $cmp_function )
public void
unserialize ( <span
class="methodparam">string
$serialized )
public bool valid ( <span class="methodparam">void )
}
预定义常量
ArrayIterator 标记
ArrayIterator::STD_PROP_LIST
Properties of the object have their normal functionality when accessed
as list (var_dump, foreach, etc.).
ArrayIterator::ARRAY_AS_PROPS
可以通过属性访问条目(读写都支持)。
ArrayIterator::append
Append an element
说明
public void
ArrayIterator::append ( <span
class="methodparam">mixed $value )
Appends value as the last element.
Warning
本函数还未编写文档,仅有参数列表。
参数
value
The value to append.
返回值
没有返回值。
注释
Note:
This method cannot be called when the <span class="classname">ArrayIterator refers to an <span class="type">object.
参见
- ArrayIterator::next
ArrayIterator::asort
Sort array by values
说明
public void ArrayIterator::asort ( <span class="methodparam">void )
Sorts an array by values.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- ArrayIterator::ksort
- ArrayIterator::natcasesort
- ArrayIterator::natsort
ArrayIterator::__construct
Construct an ArrayIterator
说明
public <span
class="methodname">ArrayIterator::__construct ([ <span
class="methodparam">mixed $array<span
class="initializer"> = array() [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
Constructs an ArrayIterator <span class="type">object.
Warning
本函数还未编写文档,仅有参数列表。
参数
array
The array or object to be iterated on.
flags
Flags to control the behaviour of the <span
class="classname">ArrayIterator object. See <span
class="methodname">ArrayIterator::setFlags.
返回值
An ArrayIterator <span class="type">object.
错误/异常
ArrayIterator::__construct throws an InvalidArgumentException if anything besides an array or an object is given.
参见
- ArrayIterator::getArrayCopy
ArrayIterator::count
Count elements
说明
public int <span class="methodname">ArrayIterator::count ( <span class="methodparam">void )
Gets the number of elements in the array, or the number of public properties in the object.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The number of elements or public properties in the associated <span class="type">array or object, respectively.
参见
- ArrayIterator::getFlags
ArrayIterator::current
Return current array entry
说明
public mixed ArrayIterator::current ( <span class="methodparam">void )
Get the current array entry.
参数
此函数没有参数。
返回值
The current array entry.
范例
示例 #1 ArrayIterator::current example
<?php
$array = array('1' => 'one',
'2' => 'two',
'3' => 'three');
$arrayobject = new ArrayObject($array);
for($iterator = $arrayobject->getIterator();
$iterator->valid();
$iterator->next()) {
echo $iterator->key() . ' => ' . $iterator->current() . "\n";
}
?>
以上例程会输出:
1 => one
2 => two
3 => three
ArrayIterator::getArrayCopy
Get array copy
说明
public array ArrayIterator::getArrayCopy ( <span class="methodparam">void )
Get a copy of an array.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A copy of the array, or array of public properties if ArrayIterator refers to an <span class="type">object.
参见
- ArrayIterator::valid
ArrayIterator::getFlags
Get behavior flags
说明
public int <span class="methodname">ArrayIterator::getFlags ( <span class="methodparam">void )
Gets the behavior flags of the <span class="classname">ArrayIterator. See the ArrayIterator::setFlags method for a list of the available flags.
参数
此函数没有参数。
返回值
Returns the behavior flags of the ArrayIterator.
参见
- >ArrayIterator::setFlags
- ArrayIterator::valid
ArrayIterator::key
Return current array key
说明
public mixed ArrayIterator::key ( <span class="methodparam">void )
This function returns the current array key
参数
此函数没有参数。
返回值
The current array key.
范例
示例 #1 ArrayIterator::key example
<?php
$array = array('key' => 'value');
$arrayobject = new ArrayObject($array);
$iterator = $arrayobject->getIterator();
echo $iterator->key(); //key
?>
ArrayIterator::ksort
Sort array by keys
说明
public void ArrayIterator::ksort ( <span class="methodparam">void )
Sorts an array by the keys.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- ArrayIterator::asort
- ArrayIterator::natcasesort
- ArrayIterator::natsort
ArrayIterator::natcasesort
Sort an array naturally, case insensitive
说明
public void ArrayIterator::natcasesort ( <span class="methodparam">void )
Sort the entries by values using a case insensitive "natural order" algorithm.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- ArrayIterator::asort
- ArrayIterator::ksort
- ArrayIterator::natsort
- natcasesort
ArrayIterator::natsort
Sort an array naturally
说明
public void ArrayIterator::natsort ( <span class="methodparam">void )
Sort the entries by values using "natural order" algorithm.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- ArrayIterator::asort
- ArrayIterator::ksort
- ArrayIterator::natcasesort
- natsort
ArrayIterator::next
Move to next entry
说明
public void ArrayIterator::next ( <span class="methodparam">void )
The iterator to the next entry.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 ArrayIterator::next example
<?php
$arrayobject = new ArrayObject();
$arrayobject[] = 'zero';
$arrayobject[] = 'one';
$iterator = $arrayobject->getIterator();
while($iterator->valid()) {
echo $iterator->key() . ' => ' . $iterator->current() . "\n";
$iterator->next();
}
?>
以上例程会输出:
0 => zero
1 => one
ArrayIterator::offsetExists
Check if offset exists
说明
public bool
ArrayIterator::offsetExists ( <span
class="methodparam">mixed $index )
Checks if the offset exists.
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The offset being checked.
返回值
true if the offset exists, otherwise false
参见
- ArrayIterator::valid
ArrayIterator::offsetGet
Get value for an offset
说明
public mixed
ArrayIterator::offsetGet ( <span
class="methodparam">mixed $index )
Gets the value from the provided offset.
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The offset to get the value from.
返回值
The value at offset index.
参见
- ArrayIterator::offsetSet
- ArrayIterator::offsetUnset
ArrayIterator::offsetSet
Set value for an offset
说明
public void
ArrayIterator::offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
Sets a value for a given offset.
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The index to set for.
newval
The new value to store at the index.
返回值
没有返回值。
参见
- ArrayIterator::offsetGet
- ArrayIterator::offsetUnset
ArrayIterator::offsetUnset
Unset value for an offset
说明
public void
ArrayIterator::offsetUnset ( <span
class="methodparam">mixed $index )
Unsets a value for an offset.
If iteration is in progress, and <span class="methodname">ArrayIterator::offsetUnset is used to unset the current index of iteration, the iteration position will be advanced to the next index. Since the iteration position is also advanced at the end of a foreach loop body, use of ArrayIterator::offsetUnset inside a foreach loop may result in indices being skipped.
参数
index
The offset to unset.
返回值
没有返回值。
参见
- ArrayIterator::offsetGet
- ArrayIterator::offsetSet
ArrayIterator::rewind
Rewind array back to the start
说明
public void ArrayIterator::rewind ( <span class="methodparam">void )
This rewinds the iterator to the beginning.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 ArrayIterator::rewind example
<?php
$arrayobject = new ArrayObject();
$arrayobject[] = 'zero';
$arrayobject[] = 'one';
$arrayobject[] = 'two';
$iterator = $arrayobject->getIterator();
$iterator->next();
echo $iterator->key(); //1
$iterator->rewind(); //rewinding to the beginning
echo $iterator->key(); //0
?>
ArrayIterator::seek
Seek to position
说明
public void
ArrayIterator::seek ( <span
class="methodparam">int $position )
Warning
本函数还未编写文档,仅有参数列表。
参数
position
The position to seek to.
返回值
没有返回值。
ArrayIterator::serialize
Serialize
说明
public string ArrayIterator::serialize ( <span class="methodparam">void )
Serialize.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The serialized ArrayIterator.
参见
- ArrayIterator::unserialize
ArrayIterator::setFlags
Set behaviour flags
说明
public void
ArrayIterator::setFlags ( <span
class="methodparam">string $flags )
Set the flags that change the behavior of the ArrayIterator.
参数
flags
The new ArrayIterator behavior. It takes on either a bitmask, or named
constants. Using named constants is strongly encouraged to ensure
compatibility for future versions.
The available behavior flags are listed below. The actual meanings of these flags are described in the predefined constants.
| value | constant |
|---|---|
| 1 | ArrayIterator::STD_PROP_LIST |
| 2 | ArrayIterator::ARRAY_AS_PROPS |
返回值
没有返回值。
参见
- ArrayIterator::getFlags
ArrayIterator::uasort
Sort with a user-defined comparison function and maintain index association
说明
public void
ArrayIterator::uasort ( <span
class="methodparam">callable
$cmp_function )
This method sorts the elements such that indices maintain their correlation with the values they are associated with, using a user-defined comparison function.
Note:
如果两个成员完全相同,那么它们在排序数组中的相对顺序是未定义的。
参数
cmp_function
在第一个参数小于,等于或大于第二个参数时,该比较函数必须相应地返回一个小于,等于或大于
0 的整数。
int <span
class="replaceable">callback ( <span
class="methodparam">mixed $a, <span
class="methodparam">mixed $b )
返回值
没有返回值。
参见
- ArrayIterator::asort
- ArrayIterator::uksort
- usort
ArrayIterator::uksort
Sort by keys using a user-defined comparison function
说明
public void
ArrayIterator::uksort ( <span
class="methodparam">callable
$cmp_function )
This method sorts the elements by keys using a user-supplied comparison function.
Note:
如果两个成员完全相同,那么它们在排序数组中的相对顺序是未定义的。
参数
cmp_function
在第一个参数小于,等于或大于第二个参数时,该比较函数必须相应地返回一个小于,等于或大于
0 的整数。
int <span
class="replaceable">callback ( <span
class="methodparam">mixed $a, <span
class="methodparam">mixed $b )
返回值
没有返回值。
参见
- ArrayIterator::ksort
- ArrayIterator::uasort
- uksort
ArrayIterator::unserialize
Unserialize
说明
public void
ArrayIterator::unserialize ( <span
class="methodparam">string
$serialized )
Unserialize.
Warning
本函数还未编写文档,仅有参数列表。
参数
serialized
The serialized ArrayIterator object to be unserialized.
返回值
没有返回值。
参见
- ArrayIterator::serialize
ArrayIterator::valid
Check whether array contains more entries
说明
public bool ArrayIterator::valid ( <span class="methodparam">void )
Checks if the array contains any more entries.
参数
此函数没有参数。
返回值
Returns true if the iterator is valid, otherwise false
范例
示例 #1 ArrayIterator::valid example
<?php
$array = array('1' => 'one');
$arrayobject = new ArrayObject($array);
$iterator = $arrayobject->getIterator();
var_dump($iterator->valid()); //bool(true)
$iterator->next(); // advance to the next item
//bool(false) because there is only one array element
var_dump($iterator->valid());
?>
简介
This object supports cached iteration over another iterator.
类摘要
CachingIterator
class CachingIterator <span class="ooclass"> extends IteratorIterator implements <span class="interfacename">OuterIterator <span class="oointerface">, ArrayAccess , <span class="interfacename">Countable {
/* 常量 */
const int
CachingIterator::CALL_TOSTRING = 1 ;
const int
CachingIterator::CATCH_GET_CHILD =
16 ;
const int
CachingIterator::TOSTRING_USE_KEY =
2 ;
const int
CachingIterator::TOSTRING_USE_CURRENT =
4 ;
const int
CachingIterator::TOSTRING_USE_INNER =
8 ;
const int
CachingIterator::FULL_CACHE = 256 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $flags =
self::CALL_TOSTRING ] )
public int <span class="methodname">count ( void )
public mixed current ( <span class="methodparam">void )
public array getCache ( <span class="methodparam">void )
public int <span class="methodname">getFlags ( <span class="methodparam">void )
public Iterator getInnerIterator ( <span class="methodparam">void )
public void hasNext ( <span class="methodparam">void )
public scalar key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void
offsetExists ( <span
class="methodparam">mixed $index )
public void
offsetGet ( <span
class="methodparam">string $index )
public void
offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
public void
offsetUnset ( <span
class="methodparam">string $index )
public void rewind ( <span class="methodparam">void )
public void
setFlags ( <span
class="methodparam">int $flags )
public void __toString ( <span class="methodparam">void )
public void valid ( <span class="methodparam">void )
}
预定义常量
CachingIterator::CALL_TOSTRING
Convert every element to string.
CachingIterator::CATCH_GET_CHILD
Don't throw exception in accessing children.
CachingIterator::TOSTRING_USE_KEY
Use
key
for conversion to string.
CachingIterator::TOSTRING_USE_CURRENT
Use
current
for conversion to string.
CachingIterator::TOSTRING_USE_INNER
Use
inner
for conversion to string.
CachingIterator::FULL_CACHE
Cache all read data.
CachingIterator::__construct
Construct a new CachingIterator object for the iterator
说明
public <span
class="methodname">CachingIterator::__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $flags =
self::CALL_TOSTRING ] )
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
Iterator to cache
flags
Bitmask of flags.
CachingIterator::count
The number of elements in the iterator
说明
public int <span class="methodname">CachingIterator::count ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
May return the number of elements in the iterator.
参数
此函数没有参数。
返回值
The count of the elements iterated over.
CachingIterator::current
Return the current element
说明
public mixed CachingIterator::current ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
May return the current element in the iteration.
参数
此函数没有参数。
返回值
Mixed
参见
- Iterator::current
CachingIterator::getCache
Retrieve the contents of the cache
说明
public array CachingIterator::getCache ( <span class="methodparam">void )
Retrieve the contents of the cache.
Note:
The
CachingIterator::FULL_CACHEflag must be being used.
参数
此函数没有参数。
返回值
An array containing the cache items.
错误/异常
Throws a BadMethodCallException when the
CachingIterator::FULL_CACHE flag is not being used.
范例
示例 #1 CachingIterator::getCache example
<?php
$iterator = new ArrayIterator(array(1, 2, 3));
$cache = new CachingIterator($iterator, CachingIterator::FULL_CACHE);
$cache->next();
$cache->next();
var_dump($cache->getCache());
$cache->next();
var_dump($cache->getCache());
?>
以上例程会输出:
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
CachingIterator::getFlags
Get flags used
说明
public int <span class="methodname">CachingIterator::getFlags ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Get the bitmask of the flags used for this CachingIterator instance.
参数
此函数没有参数。
返回值
Description...
CachingIterator::getInnerIterator
Returns the inner iterator
说明
public Iterator CachingIterator::getInnerIterator ( void )
Warning
本函数还未编写文档,仅有参数列表。
Returns the iterator sent to the constructor.
参数
此函数没有参数。
返回值
Returns an object implementing the Iterator interface.
CachingIterator::hasNext
Check whether the inner iterator has a valid next element
说明
public void CachingIterator::hasNext ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
CachingIterator::key
Return the key for the current element
说明
public scalar CachingIterator::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
This method may return a key for the current element.
参数
此函数没有参数。
CachingIterator::next
Move the iterator forward
说明
public void CachingIterator::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Move the iterator forward.
参数
此函数没有参数。
返回值
没有返回值。
CachingIterator::offsetExists
The offsetExists purpose
说明
public void
CachingIterator::offsetExists ( <span
class="methodparam">mixed $index )
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The index being checked.
返回值
Returns true if an entry referenced by the offset exists,
false otherwise.
CachingIterator::offsetGet
The offsetGet purpose
说明
public void
CachingIterator::offsetGet ( <span
class="methodparam">string $index )
Warning
本函数还未编写文档,仅有参数列表。
参数
index
Description...
返回值
Description...
CachingIterator::offsetSet
The offsetSet purpose
说明
public void
CachingIterator::offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The index of the element to be set.
newval
The new value for the index.
返回值
没有返回值。
CachingIterator::offsetUnset
The offsetUnset purpose
说明
public void
CachingIterator::offsetUnset ( <span
class="methodparam">string $index )
Warning
本函数还未编写文档,仅有参数列表。
参数
index
The index of the element to be unset.
返回值
没有返回值。
CachingIterator::rewind
Rewind the iterator
说明
public void CachingIterator::rewind ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Rewind the iterator.
参数
此函数没有参数。
返回值
没有返回值。
CachingIterator::setFlags
The setFlags purpose
说明
public void
CachingIterator::setFlags ( <span
class="methodparam">int $flags )
Warning
本函数还未编写文档,仅有参数列表。
Set the flags for the CachingIterator object.
参数
flags
Bitmask of the flags to set.
返回值
没有返回值。
CachingIterator::__toString
Return the string representation of the current element
说明
public void CachingIterator::__toString ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Get the string representation of the current element.
参数
此函数没有参数。
返回值
The string representation of the current element.
CachingIterator::valid
Check whether the current element is valid
说明
public void CachingIterator::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Check whether the current element is valid.
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
简介
类摘要
CallbackFilterIterator
class CallbackFilterIterator <span class="ooclass"> extends FilterIterator implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator , <span
class="type">callable $callback )
public bool accept ( <span class="methodparam">void )
/* 继承的方法 */
public <span class="modifier">abstract bool <span class="methodname">FilterIterator::accept ( <span class="methodparam">void )
public <span
class="methodname">FilterIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
public mixed FilterIterator::current ( <span class="methodparam">void )
public Iterator FilterIterator::getInnerIterator ( <span class="methodparam">void )
public mixed FilterIterator::key ( <span class="methodparam">void )
public void FilterIterator::next ( <span class="methodparam">void )
public void FilterIterator::rewind ( <span class="methodparam">void )
public bool FilterIterator::valid ( <span class="methodparam">void )
}
范例
The callback should accept up to three arguments: the current item, the current key and the iterator, respectively.
示例 #1 Available callback arguments
<?php
/**
* Callback for CallbackFilterIterator
*
* @param $current Current item's value
* @param $key Current item's key
* @param $iterator Iterator being filtered
* @return boolean TRUE to accept the current item, FALSE otherwise
*/
function my_callback($current, $key, $iterator) {
// Your filtering code here
}
?>
Any callable may be used; such as a string containing a function name, an array for a method, or an anonymous function.
示例 #2 Callback basic examples
<?php
$dir = new FilesystemIterator(__DIR__);
// Filter large files ( > 100MB)
function is_large_file($current) {
return $current->isFile() && $current->getSize() > 104857600;
}
$large_files = new CallbackFilterIterator($dir, 'is_large_file');
// Filter directories
$files = new CallbackFilterIterator($dir, function ($current, $key, $iterator) {
return $current->isDir() && ! $iterator->isDot();
});
?>
CallbackFilterIterator::accept
Calls the callback with the current value, the current key and the inner iterator as arguments
说明
public bool CallbackFilterIterator::accept ( <span class="methodparam">void )
This method calls the callback with the current value, current key and the inner iterator.
The callback is expected to return true if the current item is to
be accepted, or false otherwise.
参数
此函数没有参数。
返回值
Returns true to accept the current item, or false otherwise.
参见
- CallbackFilterIterator Examples
- <span class="methodname">CallbackFilterIterator::__construct
CallbackFilterIterator::__construct
Create a filtered iterator from another iterator
说明
public <span
class="methodname">CallbackFilterIterator::__construct ( <span
class="methodparam">Iterator
$iterator , <span
class="type">callable $callback )
Creates a filtered iterator using the callback to determine which
items are accepted or rejected.
参数
iterator
The iterator to be filtered.
callback
The callback, which should return true to accept the current item
or false otherwise. See
Examples.
May be any valid callable value.
返回值
没有返回值。
参见
- CallbackFilterIterator Examples
- CallbackFilterIterator::accept
简介
The DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.
类摘要
DirectoryIterator
class DirectoryIterator <span class="ooclass"> extends SplFileInfo implements <span class="interfacename">SeekableIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $path )
public <span class="type">DirectoryIterator <span class="methodname">current ( <span class="methodparam">void )
public int <span class="methodname">getATime ( <span class="methodparam">void )
public string
getBasename ([ <span
class="methodparam"> string $suffix
] )
public int <span class="methodname">getCTime ( <span class="methodparam">void )
public string getExtension ( <span class="methodparam">void )
public string getFilename ( <span class="methodparam">void )
public int <span class="methodname">getGroup ( <span class="methodparam">void )
public int <span class="methodname">getInode ( <span class="methodparam">void )
public int <span class="methodname">getMTime ( <span class="methodparam">void )
public int <span class="methodname">getOwner ( <span class="methodparam">void )
public string getPath ( <span class="methodparam">void )
public string getPathname ( <span class="methodparam">void )
public int <span class="methodname">getPerms ( <span class="methodparam">void )
public int <span class="methodname">getSize ( <span class="methodparam">void )
public string getType ( <span class="methodparam">void )
public bool isDir ( <span class="methodparam">void )
public bool isDot ( <span class="methodparam">void )
public bool isExecutable ( <span class="methodparam">void )
public bool isFile ( <span class="methodparam">void )
public bool isLink ( <span class="methodparam">void )
public bool isReadable ( <span class="methodparam">void )
public bool isWritable ( <span class="methodparam">void )
public string key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
seek ( <span
class="type">int $position )
public string __toString ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
}
更新日志
| 版本 | 说明 |
|---|---|
| 5.1.2 | DirectoryIterator extends SplFileInfo. |
DirectoryIterator::__construct
Constructs a new directory iterator from a path
说明
public <span
class="methodname">DirectoryIterator::__construct ( <span
class="methodparam">string $path )
Constructs a new directory iterator from a path.
参数
path
The path of the directory to traverse.
错误/异常
Throws an UnexpectedValueException if the
path cannot be opened.
Throws a RuntimeException if the path
is an empty string.
范例
示例 #1 A <span class="methodname">DirectoryIterator::__construct example
This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
var_dump($fileinfo->getFilename());
}
}
?>
参见
- SplFileInfo
- Iterator
DirectoryIterator::current
Return the current DirectoryIterator item
说明
public <span class="type">DirectoryIterator <span class="methodname">DirectoryIterator::current ( <span class="methodparam">void )
Get the current DirectoryIterator item.
参数
此函数没有参数。
返回值
The current DirectoryIterator item.
范例
示例 #1 A DirectoryIterator::current example
This example will list the contents of the directory containing the script.
<?php
$iterator = new DirectoryIterator(__DIR__);
while($iterator->valid()) {
$file = $iterator->current();
echo $iterator->key() . " => " . $file->getFilename() . "\n";
$iterator->next();
}
?>
以上例程的输出类似于:
0 => .
1 => ..
2 => apple.jpg
3 => banana.jpg
4 => index.php
5 => pear.jpg
参见
- DirectoryIterator::key
- DirectoryIterator::next
- DirectoryIterator::rewind
- DirectoryIterator::valid
- Iterator::current
DirectoryIterator::getATime
Get last access time of the current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getATime ( <span class="methodparam">void )
Get the last access time of the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the time the file was last accessed, as a Unix timestamp.
范例
示例 #1 A DirectoryIterator::getATime example
Displays a list of the files in the directory of the script and their last access times.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getFilename() . " " . $fileinfo->getATime() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg 1240047118
banana.jpg 1240065176
index.php 1240047208
pear.jpg 12240047979
参见
- DirectoryIterator::getCTime
- DirectoryIterator::getMTime
- fileatime
DirectoryIterator::getBasename
Get base name of current DirectoryIterator item
说明
public string
DirectoryIterator::getBasename ([ <span
class="methodparam"> string $suffix
] )
Get the base name of the current <span class="classname">DirectoryIterator item.
参数
suffix
If the base name ends in suffix, this will be cut.
返回值
The base name of the current <span class="classname">DirectoryIterator item.
范例
示例 #1 A <span class="methodname">DirectoryIterator::getBasename example
This example will list the full base name and the base name with suffix .jpg removed for the files in the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getBasename() . "\n";
echo $fileinfo->getBasename('.jpg') . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg
apple
banana.jpg
banana
index.php
index.php
pear.jpg
pear
参见
- DirectoryIterator::getFilename
- DirectoryIterator::getPath
- DirectoryIterator::getPathname
- basename
- pathinfo
DirectoryIterator::getCTime
Get inode change time of the current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getCTime ( <span class="methodparam">void )
Get the inode change time for the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the last change time of the file, as a Unix timestamp.
范例
示例 #1 DirectoryIterator::getCTime example
This example displays the file name and last change time of the files in the directory containing the script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getFilename() . " changed at " . $fileinfo->getCTime() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg changed at 1240398312
banana.jpg changed at 1238605440
index.php changed at 1240398935
pear.jpg changed at 1237423740
参见
- DirectoryIterator::getATime
- DirectoryIterator::getMTime
- filectime
DirectoryIterator::getExtension
Gets the file extension
说明
public string DirectoryIterator::getExtension ( <span class="methodparam">void )
Retrieves the file extension.
参数
此函数没有参数。
返回值
Returns a string containing the file extension, or an empty string if the file has no extension.
范例
示例 #1 DirectoryIterator::getExtension example
<?php
$directory = new DirectoryIterator(__DIR__);
foreach ($directory as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getExtension() . "\n";
}
}
?>
以上例程的输出类似于:
php
txt
jpg
gz
注释
Note:
This method is only available as of PHP 5.3.6. Another way of getting the extension is to use the pathinfo function.
<?php $extension = pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION); ?>
参见
- DirectoryIterator::getFilename
- DirectoryIterator::getBasename
- pathinfo
DirectoryIterator::getFilename
Return file name of current DirectoryIterator item
说明
public string DirectoryIterator::getFilename ( <span class="methodparam">void )
Get the file name of the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the file name of the current <span class="classname">DirectoryIterator item.
范例
示例 #1 A <span class="methodname">DirectoryIterator::getFilename example
This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
echo $fileinfo->getFilename() . "\n";
}
?>
以上例程的输出类似于:
.
..
apple.jpg
banana.jpg
index.php
pear.jpg
参见
- DirectoryIterator::getBasename
- DirectoryIterator::getPath
- DirectoryIterator::getPathname
- pathinfo
DirectoryIterator::getGroup
Get group for the current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getGroup ( <span class="methodparam">void )
Get the group id of the file.
参数
此函数没有参数。
返回值
Returns the group id of the current <span class="classname">DirectoryIterator item in numerical format.
范例
示例 #1 DirectoryIterator::getGroup example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
$groupid = $iterator->getGroup();
echo 'Directory belongs to group id ' . $groupid . "\n";
print_r(posix_getgrgid($groupid));
?>
以上例程的输出类似于:
Directory belongs to group id 42
Array
(
[name] => toons
[passwd] => x
[members] => Array
(
[0] => tom
[1] => jerry
)
[gid] => 42
)
参见
- DirectoryIterator::getiNode
- DirectoryIterator::getOwner
- DirectoryIterator::getPerms
- filegroup
- posix_getgrgid
DirectoryIterator::getInode
Get inode for the current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getInode ( <span class="methodparam">void )
Get the inode number for the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the inode number for the file.
范例
示例 #1 DirectoryIterator::getInode example
This example displays the inode number for the directory containing the script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
echo $iterator->getInode();
?>
参见
- DirectoryIterator::getGroup
- DirectoryIterator::getOwner
- DirectoryIterator::getPerms
- fileinode
DirectoryIterator::getMTime
Get last modification time of current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getMTime ( <span class="methodparam">void )
Get the last modification time of the current <span class="classname">DirectoryIterator item, as a Unix timestamp.
参数
此函数没有参数。
返回值
The last modification time of the file, as a Unix timestamp.
范例
示例 #1 A DirectoryIterator::getMTime example
Displays a list of the files in the directory of the script and their last modified times.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getFilename() . " " . $fileinfo->getMTime() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg 1240047118
banana.jpg 1240065176
index.php 1240047208
pear.jpg 12240047979
参见
- DirectoryIterator::getATime
- DirectoryIterator::getCTime
- filemtime
DirectoryIterator::getOwner
Get owner of current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getOwner ( <span class="methodparam">void )
Get the owner of the current <span class="classname">DirectoryIterator item, in numerical format.
参数
此函数没有参数。
返回值
The file owner of the file, in numerical format.
范例
示例 #1 DirectoryIterator::getOwner example
This example displays the owner of the directory which contains the script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
print_r(posix_getpwuid($iterator->getOwner()));
?>
以上例程的输出类似于:
Array
(
[name] => tom
[passwd] => x
[uid] => 501
[gid] => 42
[gecos] => Tom Cat
[dir] => /home/tom
[shell] => /bin/bash
)
参见
- DirectoryIterator::getGroup
- DirectoryIterator::getiNode
- DirectoryIterator::getPerms
- posix_getpwuid
DirectoryIterator::getPath
Get path of current Iterator item without filename
说明
public string DirectoryIterator::getPath ( <span class="methodparam">void )
Get the path to the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the path to the file, omitting the file name and any trailing slash.
范例
示例 #1 DirectoryIterator::getPath example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
echo $iterator->getPath();
?>
以上例程的输出类似于:
/home/examples/public_html
参见
- DirectoryIterator::getBasename
- DirectoryIterator::getFilename
- DirectoryIterator::getPathname
- pathinfo
DirectoryIterator::getPathname
Return path and file name of current DirectoryIterator item
说明
public string DirectoryIterator::getPathname ( <span class="methodparam">void )
Get the path and file name of the current file.
参数
此函数没有参数。
返回值
Returns the path and file name of current file. Directories do not have a trailing slash.
范例
示例 #1 DirectoryIterator::getPathname example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
echo $fileinfo->getPathname() . "\n";
}
?>
以上例程的输出类似于:
/home/examples/.
/home/examples/..
/home/examples/apple.jpg
/home/examples/banana.jpg
/home/examples/getpathname.php
/home/examples/pear.jpg
参见
- DirectoryIterator::getBasename
- DirectoryIterator::getFilename
- DirectoryIterator::getPath
- pathinfo
DirectoryIterator::getPerms
Get the permissions of current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getPerms ( <span class="methodparam">void )
Get the permissions of the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the permissions of the file, as a decimal <span class="type">int.
范例
示例 #1 DirectoryIterator::getPerms example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isDot()) {
$octal_perms = substr(sprintf('%o', $fileinfo->getPerms()), -4);
echo $fileinfo->getFilename() . " " . $octal_perms . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg 0644
banana.jpg 0644
index.php 0744
pear.jpg 0644
参见
- DirectoryIterator::isExecutable
- DirectoryIterator::isReadable
- DirectoryIterator::isWritable
DirectoryIterator::getSize
Get size of current DirectoryIterator item
说明
public int <span class="methodname">DirectoryIterator::getSize ( <span class="methodparam">void )
Get the file size for the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the size of the file, in bytes.
范例
示例 #1 DirectoryIterator::getSize example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getFilename() . " " . $fileinfo->getSize() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg 15385
banana.jpg 15190
example.php 170
pear.jpg 34406
参见
- filesize
DirectoryIterator::getType
Determine the type of the current DirectoryIterator item
说明
public string DirectoryIterator::getType ( <span class="methodparam">void )
Determines which file type the current <span class="classname">DirectoryIterator item belongs to. One of file, link, or dir.
参数
此函数没有参数。
返回值
Returns a string representing the type of the file. May be one of file, link, or dir.
范例
示例 #1 DirectoryIterator::getType example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
echo $fileinfo->getFilename() . " " . $fileinfo->getType() . "\n";
}
?>
以上例程的输出类似于:
. dir
.. dir
apple.jpg file
banana.jpg file
example.php file
pear.jpg file
参见
- DirectoryIterator::isDir
- DirectoryIterator::isDot
- DirectoryIterator::isFile
- DirectoryIterator::isLink
DirectoryIterator::isDir
Determine if current DirectoryIterator item is a directory
说明
public bool DirectoryIterator::isDir ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is a directory.
参数
此函数没有参数。
返回值
Returns true if it is a directory, otherwise false
范例
示例 #1 DirectoryIterator::isDir example
This example lists the directories within the directory of the current script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isDir()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
.
..
apples
bananas
pears
参见
- DirectoryIterator::getType
- DirectoryIterator::isDot
- DirectoryIterator::isFile
- DirectoryIterator::isLink
DirectoryIterator::isDot
Determine if current DirectoryIterator item is '.' or '..'
说明
public bool DirectoryIterator::isDot ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is a directory and either . or ..
参数
此函数没有参数。
返回值
true if the entry is . or .., otherwise false
范例
示例 #1 A DirectoryIterator::isDot example
This example will list all files, omitting the . and .. entries.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isDot()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
example.php
pears.jpg
参见
- DirectoryIterator::getType
- DirectoryIterator::isDir
- DirectoryIterator::isFile
- DirectoryIterator::isLink
DirectoryIterator::isExecutable
Determine if current DirectoryIterator item is executable
说明
public bool DirectoryIterator::isExecutable ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is executable.
参数
此函数没有参数。
返回值
Returns true if the entry is executable, otherwise false
范例
示例 #1 DirectoryIterator::isExecutable example
This example lists files in the directory containing the script which are executable.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isExecutable()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
example.php
myscript.sh
参见
- DirectoryIterator::isReadable
- DirectoryIterator::isWritable
- DirectoryIterator::getPerms
DirectoryIterator::isFile
Determine if current DirectoryIterator item is a regular file
说明
public bool DirectoryIterator::isFile ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is a regular file.
参数
此函数没有参数。
返回值
Returns true if the file exists and is a regular file (not a
link or dir), otherwise false
范例
示例 #1 DirectoryIterator::isFile example
This example will list all regular files in the directory containing the script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
example.php
pears.jpg
参见
- DirectoryIterator::getType
- DirectoryIterator::isDir
- DirectoryIterator::isDot
- DirectoryIterator::isLink
DirectoryIterator::isLink
Determine if current DirectoryIterator item is a symbolic link
说明
public bool DirectoryIterator::isLink ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is a symbolic link.
参数
此函数没有参数。
返回值
Returns true if the item is a symbolic link, otherwise false
范例
示例 #1 A DirectoryIterator::isLink example
This example contains a recursive function for removing a directory tree.
<?php
/**
* This function will recursively delete all files in the given path, without
* following symlinks.
*
* @param string $path Path to the directory to remove.
*/
function removeDir($path) {
$dir = new DirectoryIterator($path);
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile() || $fileinfo->isLink()) {
unlink($fileinfo->getPathName());
} elseif (!$fileinfo->isDot() && $fileinfo->isDir()) {
removeDir($fileinfo->getPathName());
}
}
rmdir($path);
}
removeDir('foo');
?>
参见
- DirectoryIterator::getType
- DirectoryIterator::isDir
- DirectoryIterator::isDot
- DirectoryIterator::isFile
DirectoryIterator::isReadable
Determine if current DirectoryIterator item can be read
说明
public bool DirectoryIterator::isReadable ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is readable.
参数
此函数没有参数。
返回值
Returns true if the file is readable, otherwise false
范例
示例 #1 DirectoryIterator::isReadable example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isReadable()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
example.php
pears.jpg
参见
- DirectoryIterator::isExecutable
- DirectoryIterator::isWritable
- DirectoryIterator::getPerms
DirectoryIterator::isWritable
Determine if current DirectoryIterator item can be written to
说明
public bool DirectoryIterator::isWritable ( <span class="methodparam">void )
Determines if the current <span class="classname">DirectoryIterator item is writable.
参数
此函数没有参数。
返回值
Returns true if the file/directory is writable, otherwise
false
范例
示例 #1 DirectoryIterator::isWritable example
This example lists the files and directories which can be opened for writing in the directory containing the script.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isWritable()) {
echo $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
apples.txt
bananas.html
pears
参见
- DirectoryIterator::getPerms
- DirectoryIterator::isExecutable
- DirectoryIterator::isReadable
DirectoryIterator::key
Return the key for the current DirectoryIterator item
说明
public string DirectoryIterator::key ( <span class="methodparam">void )
Get the key for the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
The key for the current DirectoryIterator item.
范例
示例 #1 A DirectoryIterator::key example
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
echo $fileinfo->key() . " => " . $fileinfo->getFilename() . "\n";
}
}
?>
以上例程的输出类似于:
0 => apple.jpg
1 => banana.jpg
2 => index.php
3 => pear.jpg
参见
- DirectoryIterator::current
- DirectoryIterator::next
- DirectoryIterator::rewind
- DirectoryIterator::valid
- Iterator::key
DirectoryIterator::next
Move forward to next DirectoryIterator item
说明
public void DirectoryIterator::next ( <span class="methodparam">void )
Move forward to the next <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 DirectoryIterator::next example
List the contents of a directory using a while loop.
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
while($iterator->valid()) {
echo $iterator->getFilename() . "\n";
$iterator->next();
}
?>
以上例程的输出类似于:
.
..
apple.jpg
banana.jpg
index.php
pear.jpg
参见
- DirectoryIterator::current
- DirectoryIterator::key
- DirectoryIterator::rewind
- DirectoryIterator::valid
- Iterator::next
DirectoryIterator::rewind
Rewind the DirectoryIterator back to the start
说明
public void DirectoryIterator::rewind ( <span class="methodparam">void )
Rewind the DirectoryIterator back to the start.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 DirectoryIterator::rewind example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
$iterator->next();
echo $iterator->key(); //1
$iterator->rewind(); //rewinding to the beginning
echo $iterator->key(); //0
?>
参见
- DirectoryIterator::current
- DirectoryIterator::key
- DirectoryIterator::next
- DirectoryIterator::valid
- Iterator::rewind
DirectoryIterator::seek
Seek to a DirectoryIterator item
说明
public void
DirectoryIterator::seek ( <span
class="methodparam">int $position )
Seek to a given position in the <span class="classname">DirectoryIterator.
参数
position
The zero-based numeric position to seek to.
返回值
没有返回值。
范例
示例 #1 DirectoryIterator::seek example
Seek to the fourth item in the directory containing the script. The first two are usually . and ..
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
$iterator->seek(3);
if ($iterator->valid()) {
echo $iterator->getFilename();
} else {
echo 'No file at position 3';
}
?>
参见
- DirectoryIterator::rewind
- DirectoryIterator::next
- SeekableIterator::seek
DirectoryIterator::__toString
Get file name as a string
说明
public string DirectoryIterator::__toString ( <span class="methodparam">void )
Get the file name of the current <span class="classname">DirectoryIterator item.
参数
此函数没有参数。
返回值
Returns the file name of the current <span class="classname">DirectoryIterator item.
范例
示例 #1 A <span class="methodname">DirectoryIterator::__toString example
This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
echo $fileinfo;
}
?>
以上例程的输出类似于:
.
..
apple.jpg
banana.jpg
index.php
pear.jpg
参见
- DirectoryIterator::getFilename
- The __toString() magic method
DirectoryIterator::valid
Check whether current DirectoryIterator position is a valid file
说明
public bool DirectoryIterator::valid ( <span class="methodparam">void )
Check whether current DirectoryIterator position is a valid file.
参数
此函数没有参数。
返回值
Returns true if the position is valid, otherwise false
范例
示例 #1 A DirectoryIterator::valid example
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
// Loop to end of iterator
while($iterator->valid()) {
$iterator->next();
}
$iterator->valid(); // FALSE
$iterator->rewind();
$iterator->valid(); // TRUE
?>
参见
- DirectoryIterator::current
- DirectoryIterator::key
- DirectoryIterator::next
- DirectoryIterator::rewind
- Iterator::valid
简介
The EmptyIterator class for an empty iterator.
类摘要
EmptyIterator
class EmptyIterator <span class="oointerface">implements <span class="interfacename">Iterator {
/* 方法 */
public mixed current ( <span class="methodparam">void )
public scalar key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
}
EmptyIterator::current
The current() method
说明
public mixed EmptyIterator::current ( <span class="methodparam">void )
This function must not be called. It throws an exception upon access.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
错误/异常
Throws an Exception if called.
返回值
没有返回值。
EmptyIterator::key
The key() method
说明
public scalar EmptyIterator::key ( <span class="methodparam">void )
This function must not be called. It throws an exception upon access.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
错误/异常
Throws an Exception if called.
返回值
没有返回值。
EmptyIterator::next
The next() method
说明
public void EmptyIterator::next ( <span class="methodparam">void )
No operation, nothing to do.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
EmptyIterator::rewind
The rewind() method
说明
public void EmptyIterator::rewind ( <span class="methodparam">void )
No operation, nothing to do.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
EmptyIterator::valid
The valid() method
说明
public bool EmptyIterator::valid ( <span class="methodparam">void )
The EmptyIterator valid() method.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
false
简介
The Filesystem iterator
类摘要
FilesystemIterator
class FilesystemIterator <span class="ooclass"> extends DirectoryIterator implements <span class="interfacename">SeekableIterator {
/* 常量 */
const int
FilesystemIterator::CURRENT_AS_PATHNAME =
32 ;
const int
FilesystemIterator::CURRENT_AS_FILEINFO =
0 ;
const int
FilesystemIterator::CURRENT_AS_SELF =
16 ;
const int
FilesystemIterator::CURRENT_MODE_MASK =
240 ;
const int
FilesystemIterator::KEY_AS_PATHNAME =
0 ;
const int
FilesystemIterator::KEY_AS_FILENAME =
256 ;
const int
FilesystemIterator::FOLLOW_SYMLINKS =
512 ;
const int
FilesystemIterator::KEY_MODE_MASK =
3840 ;
const int
FilesystemIterator::NEW_CURRENT_AND_KEY =
256 ;
const int
FilesystemIterator::SKIP_DOTS = 4096
;
const int
FilesystemIterator::UNIX_PATHS =
8192 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $path [,
int $flags<span
class="initializer"> = FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS ] )
public mixed current ( <span class="methodparam">void )
public int <span class="methodname">getFlags ( <span class="methodparam">void )
public string key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
setFlags ([ <span
class="methodparam">int $flags ] )
/* 继承的方法 */
public <span class="type">DirectoryIterator <span class="methodname">DirectoryIterator::current ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getATime ( <span class="methodparam">void )
public string
DirectoryIterator::getBasename ([ <span
class="methodparam"> string $suffix
] )
public int <span class="methodname">DirectoryIterator::getCTime ( <span class="methodparam">void )
public string DirectoryIterator::getExtension ( <span class="methodparam">void )
public string DirectoryIterator::getFilename ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getGroup ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getInode ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getMTime ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getOwner ( <span class="methodparam">void )
public string DirectoryIterator::getPath ( <span class="methodparam">void )
public string DirectoryIterator::getPathname ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getPerms ( <span class="methodparam">void )
public int <span class="methodname">DirectoryIterator::getSize ( <span class="methodparam">void )
public string DirectoryIterator::getType ( <span class="methodparam">void )
public bool DirectoryIterator::isDir ( <span class="methodparam">void )
public bool DirectoryIterator::isDot ( <span class="methodparam">void )
public bool DirectoryIterator::isExecutable ( <span class="methodparam">void )
public bool DirectoryIterator::isFile ( <span class="methodparam">void )
public bool DirectoryIterator::isLink ( <span class="methodparam">void )
public bool DirectoryIterator::isReadable ( <span class="methodparam">void )
public bool DirectoryIterator::isWritable ( <span class="methodparam">void )
public string DirectoryIterator::key ( <span class="methodparam">void )
public void DirectoryIterator::next ( <span class="methodparam">void )
public void DirectoryIterator::rewind ( <span class="methodparam">void )
public void
DirectoryIterator::seek ( <span
class="methodparam">int $position )
public string DirectoryIterator::__toString ( <span class="methodparam">void )
public bool DirectoryIterator::valid ( <span class="methodparam">void )
}
预定义常量
FilesystemIterator::CURRENT_AS_PATHNAME
Makes FilesystemIterator::current return
the pathname.
FilesystemIterator::CURRENT_AS_FILEINFO
Makes FilesystemIterator::current return
an SplFileInfo instance.
FilesystemIterator::CURRENT_AS_SELF
Makes FilesystemIterator::current return
$this (the FilesystemIterator).
FilesystemIterator::CURRENT_MODE_MASK
Masks FilesystemIterator::current
FilesystemIterator::KEY_AS_PATHNAME
Makes FilesystemIterator::key return the
pathname.
FilesystemIterator::KEY_AS_FILENAME
Makes FilesystemIterator::key return the
filename.
FilesystemIterator::FOLLOW_SYMLINKS
Makes <span
class="methodname">RecursiveDirectoryIterator::hasChildren follow
symlinks.
FilesystemIterator::KEY_MODE_MASK
Masks FilesystemIterator::key
FilesystemIterator::NEW_CURRENT_AND_KEY
Same as FilesystemIterator::KEY_AS_FILENAME |
FilesystemIterator::CURRENT_AS_FILEINFO.
FilesystemIterator::SKIP_DOTS
Skips dot files (. and ..).
FilesystemIterator::UNIX_PATHS
Makes paths use Unix-style forward slash irrespective of system default.
Note that the path that is passed to the constructor is not modified.
更新日志
| 版本 | 说明 |
|---|---|
| 5.3.1 | Added FilesystemIterator::FOLLOW_SYMLINKS |
FilesystemIterator::__construct
Constructs a new filesystem iterator
说明
public <span
class="methodname">FilesystemIterator::__construct ( <span
class="methodparam">string $path [,
int $flags<span
class="initializer"> = FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS ] )
Constructs a new filesystem iterator from the path.
参数
path
The path of the filesystem item to be iterated over.
flags
Flags may be provided which will affect the behavior of some methods. A
list of the flags can found under
FilesystemIterator predefined constants.
They can also be set later with <span
class="methodname">FilesystemIterator::setFlags
Note:
FilesystemIterator::SKIP_DOTSis always set, and cannot be removed.
返回值
没有返回值。
错误/异常
Throws an UnexpectedValueException if the
path cannot be found.
范例
示例 #1 <span class="function">FilesystemIterator::__construct example
<?php
$it = new FilesystemIterator(dirname(__FILE__));
foreach ($it as $fileinfo) {
echo $fileinfo->getFilename() . "\n";
}
?>
以上例程会输出:
apples.jpg
banana.jpg
example.php
参见
- FilesystemIterator::setFlags
- DirectoryIterator::__construct
FilesystemIterator::current
The current file
说明
public mixed FilesystemIterator::current ( <span class="methodparam">void )
Get file information of the current element.
参数
此函数没有参数。
返回值
The filename, file information, or $this depending on the set flags. See the FilesystemIterator constants.
范例
示例 #1 FilesystemIterator::current example
This example will list the contents of the directory containing the script.
<?php
$iterator = new FilesystemIterator(__DIR__, FilesystemIterator::CURRENT_AS_PATHNAME);
foreach ($iterator as $fileinfo) {
echo $iterator->current() . "\n";
}
?>
以上例程的输出类似于:
/www/examples/apple.jpg
/www/examples/banana.jpg
/www/examples/example.php
参见
- FilesystemIterator constants
- DirectoryIterator::current
- DirectoryIterator::getFileName
FilesystemIterator::getFlags
Get the handling flags
说明
public int <span class="methodname">FilesystemIterator::getFlags ( <span class="methodparam">void )
Gets the handling flags, as set in <span class="methodname">FilesystemIterator::__construct or <span class="methodname">FilesystemIterator::setFlags.
参数
此函数没有参数。
返回值
The integer value of the set flags.
参见
- FilesystemIterator::__construct
- FilesystemIterator::setFlags
FilesystemIterator::key
Retrieve the key for the current file
说明
public string FilesystemIterator::key ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Returns the pathname or filename depending on the set flags. See the FilesystemIterator constants.
范例
示例 #1 FilesystemIterator::key example
This example will list the contents of the directory containing the script.
<?php
$iterator = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_FILENAME);
foreach ($iterator as $fileinfo) {
echo $iterator->key() . "\n";
}
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
example.php
参见
- FilesystemIterator constants
- DirectoryIterator::key
- DirectoryIterator::getFilename
- DirectoryIterator::getPathname
FilesystemIterator::next
Move to the next file
说明
public void FilesystemIterator::next ( <span class="methodparam">void )
Move to the next file.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 FilesystemIterator::next example
List the contents of a directory using a while loop.
<?php
$iterator = new FilesystemIterator(dirname(__FILE__));
while($iterator->valid()) {
echo $iterator->getFilename() . "\n";
$iterator->next();
}
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
example.php
参见
- DirectoryIterator::next
FilesystemIterator::rewind
Rewinds back to the beginning
说明
public void FilesystemIterator::rewind ( <span class="methodparam">void )
Rewinds the directory back to the start.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 FilesystemIterator::rewind example
<?php
$iterator = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_FILENAME);
echo $iterator->key() . "\n";
$iterator->next();
echo $iterator->key() . "\n";
$iterator->rewind();
echo $iterator->key() . "\n";
?>
以上例程的输出类似于:
apple.jpg
banana.jpg
apple.jpg
参见
- DirectoryIterator::rewind
FilesystemIterator::setFlags
Sets handling flags
说明
public void
FilesystemIterator::setFlags ([ <span
class="methodparam">int $flags ] )
Sets handling flags.
参数
flags
The handling flags to set. See the
FilesystemIterator constants.
返回值
没有返回值。
范例
示例 #1 FilesystemIterator::key example
This example demonstrates the difference between the FilesystemIterator::KEY_AS_PATHNAME and FilesystemIterator::KEY_AS_FILENAME flags.
<?php
$iterator = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_PATHNAME);
echo "Key as Pathname:\n";
foreach ($iterator as $key => $fileinfo) {
echo $key . "\n";
}
$iterator->setFlags(FilesystemIterator::KEY_AS_FILENAME);
echo "\nKey as Filename:\n";
foreach ($iterator as $key => $fileinfo) {
echo $key . "\n";
}
?>
以上例程的输出类似于:
Key as Pathname:
/www/examples/apple.jpg
/www/examples/banana.jpg
/www/examples/example.php
Key as Filename:
apple.jpg
banana.jpg
example.php
参见
- FilesystemIterator::__construct
- FilesystemIterator::getFlags
简介
这个抽象类的遍历并过滤出不想要的值.这个类应该被实现了迭代过滤器的类继承 <span class="methodname">FilterIterator::accept方法必须被子类实现.
类摘要
FilterIterator
abstract class FilterIterator <span class="modifier">extends IteratorIterator <span class="oointerface">implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span class="modifier">abstract bool <span class="methodname">accept ( void )
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator )
public mixed current ( <span class="methodparam">void )
public Iterator getInnerIterator ( <span class="methodparam">void )
public mixed key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
}
FilterIterator::accept
Check whether the current element of the iterator is acceptable
说明
public <span class="modifier">abstract bool <span class="methodname">FilterIterator::accept ( <span class="methodparam">void )
Returns whether the current element of the iterator is acceptable through this filter.
参数
此函数没有参数。
返回值
true if the current element is acceptable, otherwise false.
范例
示例 #1 FilterIterator::accept example
<?php
// This iterator filters all values with less than 10 characters
class LengthFilterIterator extends FilterIterator {
public function accept() {
// Only accept strings with a length of 10 and greater
return strlen(parent::current()) >= 10;
}
}
$arrayIterator = new ArrayIterator(array('test1', 'more than 10 characters'));
$lengthFilter = new LengthFilterIterator($arrayIterator);
foreach ($lengthFilter as $value) {
echo $value . "\n";
}
?>
以上例程会输出:
more than 10 characters
FilterIterator::__construct
Construct a filterIterator
说明
public <span
class="methodname">FilterIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
Constructs a new FilterIterator, which
consists of a passed in iterator with filters applied to it.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The iterator that is being filtered.
返回值
The FilterIterator.
参见
- LimitIterator::__construct
FilterIterator::current
Get the current element value
说明
public mixed FilterIterator::current ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Get the current element value.
参数
此函数没有参数。
返回值
The current element value.
参见
- FilterIterator::key
- FilterIterator::next
FilterIterator::getInnerIterator
Get the inner iterator
说明
public Iterator FilterIterator::getInnerIterator ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Get the inner iterator.
参数
此函数没有参数。
返回值
The inner iterator.
FilterIterator::key
Get the current key
说明
public mixed FilterIterator::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Get the current key.
参数
此函数没有参数。
返回值
The current key.
参见
- FilterIterator::next
- FilterIterator::current
FilterIterator::next
Move the iterator forward
说明
public void FilterIterator::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Move the iterator forward.
参数
此函数没有参数。
返回值
没有返回值。
参见
- FilterIterator::current
- FilterIterator::key
FilterIterator::rewind
Rewind the iterator
说明
public void FilterIterator::rewind ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Rewind the iterator.
参数
此函数没有参数。
返回值
没有返回值。
参见
- FilterIterator::current
- FilterIterator::key
- FilterIterator::next
FilterIterator::valid
Check whether the current element is valid
说明
public bool FilterIterator::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
Checks whether the current element is valid.
参数
此函数没有参数。
返回值
true if the current element is valid, otherwise false
简介
遍历一个文件系统行为类似于 glob.
类摘要
GlobIterator
class GlobIterator <span class="ooclass"> extends FilesystemIterator implements SeekableIterator <span class="oointerface">, Countable {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $pattern
[, int
$flags =
FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO ] )
public int <span class="methodname">count ( void )
/* 继承的方法 */
public <span
class="methodname">FilesystemIterator::__construct ( <span
class="methodparam">string $path [,
int $flags<span
class="initializer"> = FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS ] )
public mixed FilesystemIterator::current ( <span class="methodparam">void )
public int <span class="methodname">FilesystemIterator::getFlags ( <span class="methodparam">void )
public string FilesystemIterator::key ( <span class="methodparam">void )
public void FilesystemIterator::next ( <span class="methodparam">void )
public void FilesystemIterator::rewind ( <span class="methodparam">void )
public void
FilesystemIterator::setFlags ([ <span
class="methodparam">int $flags ] )
}
GlobIterator::__construct
Construct a directory using glob
说明
public <span
class="methodname">GlobIterator::__construct ( <span
class="methodparam">string $pattern
[, int
$flags =
FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO ] )
Constructs a new directory iterator from a glob expression.
参数
pattern
A glob pattern.
flags
Option flags, the flags may be a bitmask of the <span
class="classname">FilesystemIterator constants.
范例
示例 #1 GlobIterator example
<?php
$iterator = new GlobIterator('*.dll', FilesystemIterator::KEY_AS_FILENAME);
if (!$iterator->count()) {
echo 'No matches';
} else {
$n = 0;
printf("Matched %d item(s)\r\n", $iterator->count());
foreach ($iterator as $item) {
printf("[%d] %s\r\n", ++$n, $iterator->key());
}
}
?>
以上例程的输出类似于:
Matched 2 item(s)
[1] php5ts.dll
[2] php_gd2.dll
参见
- DirectoryIterator::__construct
- GlobIterator::count
- glob
GlobIterator::count
Get the number of directories and files
说明
public int <span class="methodname">GlobIterator::count ( <span class="methodparam">void )
Gets the number of directories and files found by the glob expression.
参数
此函数没有参数。
返回值
The number of returned directories and files, as an <span class="type">int.
范例
示例 #1 GlobIterator::count example
<?php
$iterator = new GlobIterator('*.xml');
printf("Matched %d item(s)\r\n", $iterator->count());
?>
以上例程的输出类似于:
Matched 8 item(s)
参见
- GlobIterator::__construct
- count
- glob
简介
The InfiniteIterator allows one to infinitely iterate over an iterator without having to manually rewind the iterator upon reaching its end.
类摘要
InfiniteIterator
class InfiniteIterator <span class="ooclass"> extends IteratorIterator implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator )
public void next ( <span class="methodparam">void )
/* 继承的方法 */
public <span
class="methodname">IteratorIterator::__construct ( <span
class="methodparam">Traversable
$iterator )
public mixed IteratorIterator::current ( <span class="methodparam">void )
public <span class="type">Traversable <span class="methodname">IteratorIterator::getInnerIterator ( <span class="methodparam">void )
public mixed IteratorIterator::key ( <span class="methodparam">void )
public void IteratorIterator::next ( <span class="methodparam">void )
public void IteratorIterator::rewind ( <span class="methodparam">void )
public bool IteratorIterator::valid ( <span class="methodparam">void )
}
InfiniteIterator::__construct
Constructs an InfiniteIterator
说明
public <span
class="methodname">InfiniteIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
Constructs an InfiniteIterator from an Iterator.
参数
iterator
The iterator to infinitely iterate over.
返回值
没有返回值。
错误/异常
Throws an E_RECOVERABLE_ERROR if the iterator parameter is not
an Iterator.
范例
示例 #1 InfiniteIterator::__construct example
<?php
$arrayit = new ArrayIterator(array('cat','dog'));
$infinite = new InfiniteIterator($arrayit);
$limit = new LimitIterator($infinite, 0, 7);
foreach($limit as $value)
{
echo "$value\n";
}
?>
以上例程会输出:
cat
dog
cat
dog
cat
dog
cat
参见
- InfiniteIterator::next
InfiniteIterator::next
Moves the inner Iterator forward or rewinds it
说明
public void InfiniteIterator::next ( <span class="methodparam">void )
Moves the inner Iterator forward to its next element if there is one, otherwise rewinds the inner <span class="classname">Iterator back to the beginning.
Note:
Even an InfiniteIterator stops if its inner Iterator is empty.
参数
此函数没有参数。
返回值
没有返回值。
参见
- InfiniteIterator::__construct
简介
This iterator wrapper allows the conversion of anything that is Traversable into an Iterator. It is important to understand that most classes that do not implement Iterators have reasons as most likely they do not allow the full Iterator feature set. If so, techniques should be provided to prevent misuse, otherwise expect exceptions or fatal errors.
类摘要
IteratorIterator
class IteratorIterator <span class="oointerface">implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Traversable
$iterator )
public mixed current ( <span class="methodparam">void )
public <span class="type">Traversable <span class="methodname">getInnerIterator ( <span class="methodparam">void )
public mixed key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
}
注释
Note:
This class permits access to methods of the inner iterator via the __call magic method.
IteratorIterator::__construct
Create an iterator from anything that is traversable
说明
public <span
class="methodname">IteratorIterator::__construct ( <span
class="methodparam">Traversable
$iterator )
Creates an iterator from anything that is traversable.
参数
iterator
The traversable iterator.
返回值
没有返回值。
参见
- Traversable
IteratorIterator::current
Get the current value
说明
public mixed IteratorIterator::current ( <span class="methodparam">void )
Get the value of the current element.
参数
此函数没有参数。
返回值
The value of the current element.
参见
- IteratorIterator::key
IteratorIterator::getInnerIterator
Get the inner iterator
说明
public <span class="type">Traversable <span class="methodname">IteratorIterator::getInnerIterator ( <span class="methodparam">void )
Get the inner iterator.
参数
此函数没有参数。
返回值
The inner iterator as passed to <span class="methodname">IteratorIterator::__construct.
参见
- Iterator
- OuterIterator
IteratorIterator::key
Get the key of the current element
说明
public mixed IteratorIterator::key ( <span class="methodparam">void )
Get the key of the current element.
参数
此函数没有参数。
返回值
The key of the current element.
参见
- IteratorIterator::current
IteratorIterator::next
Forward to the next element
说明
public void IteratorIterator::next ( <span class="methodparam">void )
Forward to the next element.
参数
此函数没有参数。
返回值
没有返回值。
参见
- IteratorIterator::rewind
- IteratorIterator::valid
IteratorIterator::rewind
Rewind to the first element
说明
public void IteratorIterator::rewind ( <span class="methodparam">void )
Rewinds to the first element.
参数
此函数没有参数。
返回值
没有返回值。
参见
- IteratorIterator::next
- IteratorIterator::valid
IteratorIterator::valid
Checks if the iterator is valid
说明
public bool IteratorIterator::valid ( <span class="methodparam">void )
Checks if the iterator is valid.
参数
此函数没有参数。
返回值
Returns true if the iterator is valid, otherwise false
参见
- iterator_count
- IteratorIterator::current
简介
LimitIterator类允许遍历一个 <span class="classname">Iterator 的限定子集的元素.
类摘要
LimitIterator
class LimitIterator <span class="ooclass"> extends IteratorIterator implements <span class="interfacename">OuterIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $offset =
0 [, <span
class="type">int $count =
-1 ]] )
public mixed current ( <span class="methodparam">void )
public Iterator getInnerIterator ( <span class="methodparam">void )
public int <span class="methodname">getPosition ( <span class="methodparam">void )
public mixed key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public int <span
class="methodname">seek ( <span
class="type">int $position )
public bool valid ( <span class="methodparam">void )
}
范例
示例 #1 LimitIterator usage example
<?php
// Create an iterator to be limited
$fruits = new ArrayIterator(array(
'apple',
'banana',
'cherry',
'damson',
'elderberry'
));
// Loop over first three fruits only
foreach (new LimitIterator($fruits, 0, 3) as $fruit) {
var_dump($fruit);
}
echo "\n";
// Loop from third fruit until the end
// Note: offset starts from zero for apple
foreach (new LimitIterator($fruits, 2) as $fruit) {
var_dump($fruit);
}
?>
以上例程会输出:
string(5) "apple"
string(6) "banana"
string(6) "cherry"
string(6) "cherry"
string(6) "damson"
string(10) "elderberry"
LimitIterator::__construct
Construct a LimitIterator
说明
public <span
class="methodname">LimitIterator::__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $offset =
0 [, <span
class="type">int $count =
-1 ]] )
Constructs a new LimitIterator from an
iterator with a given starting offset and maximum count.
参数
iterator
The Iterator to limit.
offset
Optional offset of the limit.
count
Optional count of the limit.
返回值
The new LimitIterator.
错误/异常
Throws an OutOfRangeException if the
offset is less than 0 or the count is less than -1.
范例
示例 #1 LimitIterator::__construct example
<?php
$ait = new ArrayIterator(array('a', 'b', 'c', 'd', 'e'));
$lit = new LimitIterator($ait, 1, 3);
foreach ($lit as $value) {
echo $value . "\n";
}
?>
以上例程会输出:
b
c
d
参见
LimitIterator::current
Get current element
说明
public mixed LimitIterator::current ( <span class="methodparam">void )
Gets the current element of the inner <span class="classname">Iterator.
参数
此函数没有参数。
返回值
Returns the current element or null if there is none.
参见
- LimitIterator::key
- LimitIterator::next
- LimitIterator::rewind
- LimitIterator::seek
- LimitIterator::valid
LimitIterator::getInnerIterator
Get inner iterator
说明
public Iterator LimitIterator::getInnerIterator ( <span class="methodparam">void )
Gets the inner Iterator.
参数
此函数没有参数。
返回值
The inner iterator passed to <span class="methodname">LimitIterator::__construct.
参见
- LimitIterator::__construct
- IteratorIterator::getInnerIterator
LimitIterator::getPosition
Return the current position
说明
public int <span class="methodname">LimitIterator::getPosition ( <span class="methodparam">void )
Gets the current zero-based position of the inner <span class="classname">Iterator.
参数
此函数没有参数。
返回值
The current position.
范例
示例 #1 LimitIterator::getPosition example
<?php
$fruits = array(
'a' => 'apple',
'b' => 'banana',
'c' => 'cherry',
'd' => 'damson',
'e' => 'elderberry'
);
$array_it = new ArrayIterator($fruits);
$limit_it = new LimitIterator($array_it, 2, 3);
foreach ($limit_it as $item) {
echo $limit_it->getPosition() . ' ' . $item . "\n";
}
?>
以上例程会输出:
2 cherry
3 damson
4 elderberry
参见
- FilterIterator::key
LimitIterator::key
Get current key
说明
public mixed LimitIterator::key ( <span class="methodparam">void )
Gets the key for the current item in the inner <span class="classname">Iterator.
参数
此函数没有参数。
返回值
Returns the key for the current item.
参见
- LimitIterator::getPosition
- LimitIterator::current
- LimitIterator::next
- LimitIterator::rewind
- LimitIterator::seek
- LimitIterator::valid
LimitIterator::next
Move the iterator forward
说明
public void LimitIterator::next ( <span class="methodparam">void )
Moves the iterator forward.
参数
此函数没有参数。
返回值
没有返回值。
参见
- LimitIterator::current
- LimitIterator::key
- LimitIterator::rewind
- LimitIterator::seek
- LimitIterator::valid
LimitIterator::rewind
Rewind the iterator to the specified starting offset
说明
public void LimitIterator::rewind ( <span class="methodparam">void )
Rewinds the iterator to the starting offset specified in <span class="methodname">LimitIterator::__construct.
参数
此函数没有参数。
返回值
没有返回值。
参见
- LimitIterator::current
- LimitIterator::key
- LimitIterator::next
- LimitIterator::seek
- LimitIterator::valid
LimitIterator::seek
Seek to the given position
说明
public int <span
class="methodname">LimitIterator::seek ( <span
class="methodparam">int $position )
Moves the iterator to the offset specified by position.
参数
position
The position to seek to.
返回值
Returns the offset position after seeking.
错误/异常
Throws an OutOfBoundsException if the position is outside of the limits specified in <span class="methodname">LimitIterator::__construct.
参见
- LimitIterator::current
- LimitIterator::key
- LimitIterator::rewind
- LimitIterator::next
- LimitIterator::valid
LimitIterator::valid
Check whether the current element is valid
说明
public bool LimitIterator::valid ( <span class="methodparam">void )
Checks whether the current element is valid.
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- LimitIterator::current
- LimitIterator::key
- LimitIterator::rewind
- LimitIterator::next
- LimitIterator::seek
简介
An Iterator that sequentially iterates over all attached iterators
类摘要
MultipleIterator
class MultipleIterator <span class="oointerface">implements <span class="interfacename">Iterator {
/* 常量 */
const int
MultipleIterator::MIT_NEED_ANY = 0 ;
const int
MultipleIterator::MIT_NEED_ALL = 1 ;
const int
MultipleIterator::MIT_KEYS_NUMERIC =
0 ;
const int
MultipleIterator::MIT_KEYS_ASSOC = 2
;
/* 方法 */
public <span
class="methodname">__construct ([
int $flags =
MultipleIterator::MIT_NEED_ALL|MultipleIterator::MIT_KEYS_NUMERIC
] )
public void
attachIterator ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">string $infos ] )
public bool
containsIterator ( <span
class="methodparam">Iterator
$iterator )
public int <span class="methodname">countIterators ( <span class="methodparam">void )
public array current ( <span class="methodparam">void )
public void
detachIterator ( <span
class="methodparam">Iterator
$iterator )
public int <span class="methodname">getFlags ( <span class="methodparam">void )
public array key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
setFlags ( <span
class="methodparam">int $flags )
public bool valid ( <span class="methodparam">void )
}
预定义常量
MultipleIterator::MIT_NEED_ANY
Do not require all sub iterators to be valid in iteration.
MultipleIterator::MIT_NEED_ALL
Require all sub iterators to be valid in iteration.
MultipleIterator::MIT_KEYS_NUMERIC
Keys are created from the sub iterators position.
MultipleIterator::MIT_KEYS_ASSOC
Keys are created from sub iterators associated information.
MultipleIterator::attachIterator
Attaches iterator information
说明
public void
MultipleIterator::attachIterator ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">string $infos ] )
Attaches iterator information.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The new iterator to attach.
infos
The associative information for the Iterator, which must be an <span
class="type">int, a string, or
null.
返回值
Description...
错误/异常
An IllegalValueException if the
iterator parameter is invalid, or if infos is already associated
information.
参见
- MultipleIterator::__construct
MultipleIterator::__construct
Constructs a new MultipleIterator
说明
public <span
class="methodname">MultipleIterator::__construct ([ <span
class="methodparam"> int $flags <span
class="initializer"> =
MultipleIterator::MIT_NEED_ALL|MultipleIterator::MIT_KEYS_NUMERIC
] )
Construct a new MultipleIterator.
参数
flags
The flags to set, according to the
Flag Constants.
MultipleIterator::MIT_NEED_ALLorMultipleIterator::MIT_NEED_ANYMultipleIterator::MIT_KEYS_NUMERICorMultipleIterator::MIT_KEYS_ASSOC
Defaults to
MultipleIterator::MIT_NEED_ALL|MultipleIterator::MIT_KEYS_NUMERIC.
返回值
没有返回值。
范例
示例 #1 Iterating a MultipleIterator
<?php
$people = new ArrayIterator(array('John', 'Jane', 'Jack', 'Judy'));
$roles = new ArrayIterator(array('Developer', 'Scrum Master', 'Project Owner'));
$team = new MultipleIterator($flags);
$team->attachIterator($people, 'person');
$team->attachIterator($roles, 'role');
foreach ($team as $member) {
print_r($member);
}
?>
Output with $flags = MIT_NEED_ALL|MIT_KEYS_NUMERIC
Array
(
[0] => John
[1] => Developer
)
Array
(
[0] => Jane
[1] => Scrum Master
)
Array
(
[0] => Jack
[1] => Project Owner
)
Output with $flags = MIT_NEED_ANY|MIT_KEYS_NUMERIC
Array
(
[0] => John
[1] => Developer
)
Array
(
[0] => Jane
[1] => Scrum Master
)
Array
(
[0] => Jack
[1] => Project Owner
)
Array
(
[0] => Judy
[1] =>
)
Output with $flags = MIT_NEED_ALL|MIT_KEYS_ASSOC
Array
(
[person] => John
[role] => Developer
)
Array
(
[person] => Jane
[role] => Scrum Master
)
Array
(
[person] => Jack
[role] => Project Owner
)
Output with $flags = MIT_NEED_ANY|MIT_KEYS_ASSOC
Array
(
[person] => John
[role] => Developer
)
Array
(
[person] => Jane
[role] => Scrum Master
)
Array
(
[person] => Jack
[role] => Project Owner
)
Array
(
[person] => Judy
[role] =>
)
参见
- Flag Constants
- MultipleIterator::valid
MultipleIterator::containsIterator
Checks if an iterator is attached
说明
public bool
MultipleIterator::containsIterator (
Iterator
$iterator )
Checks if an iterator is attached or not.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The iterator to check.
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- MultipleIterator::valid
MultipleIterator::countIterators
Gets the number of attached iterator instances
说明
public int <span class="methodname">MultipleIterator::countIterators ( <span class="methodparam">void )
Gets the number of attached iterator instances.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The number of attached iterator instances (as an <span class="type">int).
参见
- MultipleIterator::containsIterator
MultipleIterator::current
Gets the registered iterator instances
说明
public array MultipleIterator::current ( <span class="methodparam">void )
Get the registered iterator instances current() result.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
An array containing the current values of each
attached iterator, or false if no iterators are attached.
错误/异常
A RuntimeException if mode
MIT_NEED_ALL is set and at least one attached iterator is not
valid. Or an IllegalValueException if a
key is null and MIT_KEYS_ASSOC is set.
参见
- MultipleIterator::valid
MultipleIterator::detachIterator
Detaches an iterator
说明
public void
MultipleIterator::detachIterator ( <span
class="methodparam">Iterator
$iterator )
Detaches an iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The iterator to detach.
返回值
没有返回值。
参见
- MultipleIterator::attachIterator
MultipleIterator::getFlags
Gets the flag information
说明
public int <span class="methodname">MultipleIterator::getFlags ( <span class="methodparam">void )
Gets information about the flags.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Information about the flags, as an int.
参见
- Flag Constants
- MultipleIterator::__construct
- MultipleIterator::setFlags
MultipleIterator::key
Gets the registered iterator instances
说明
public array MultipleIterator::key ( <span class="methodparam">void )
Get the registered iterator instances key() result.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
An array of all registered iterator instances,
or false if no sub iterator is attached.
错误/异常
A LogicException if mode
MIT_NEED_ALL is set, and at least one attached iterator is not
valid.
Calling this method from foreach triggers warning "Illegal type returned".
参见
- MultipleIterator::current
MultipleIterator::next
Moves all attached iterator instances forward
说明
public void MultipleIterator::next ( <span class="methodparam">void )
Moves all attached iterator instances forward.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- MultipleIterator::rewind
MultipleIterator::rewind
Rewinds all attached iterator instances
说明
public void MultipleIterator::rewind ( <span class="methodparam">void )
Rewinds all attached iterator instances.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- MultipleIterator::next
MultipleIterator::setFlags
Sets flags
说明
public void
MultipleIterator::setFlags ( <span
class="methodparam">int $flags )
Sets flags.
Warning
本函数还未编写文档,仅有参数列表。
参数
flags
The flags to set, according to the
Flag Constants
返回值
没有返回值。
参见
- Flag Constants
- MultipleIterator::__construct
- MultipleIterator::getFlags
MultipleIterator::valid
Checks the validity of sub iterators
说明
public bool MultipleIterator::valid ( <span class="methodparam">void )
Checks the validity of sub iterators.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns true if one or all sub iterators are valid depending on
flags, otherwise false
参见
- MultipleIterator::__construct
简介
This iterator ignores rewind operations. This allows processing an iterator in multiple partial foreach loops.
类摘要
NoRewindIterator
class NoRewindIterator <span class="ooclass"> extends IteratorIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator )
public mixed current ( <span class="methodparam">void )
public iterator getInnerIterator ( <span class="methodparam">void )
public mixed key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public bool valid ( <span class="methodparam">void )
/* 继承的方法 */
public <span
class="methodname">IteratorIterator::__construct ( <span
class="methodparam">Traversable
$iterator )
public mixed IteratorIterator::current ( <span class="methodparam">void )
public <span class="type">Traversable <span class="methodname">IteratorIterator::getInnerIterator ( <span class="methodparam">void )
public mixed IteratorIterator::key ( <span class="methodparam">void )
public void IteratorIterator::next ( <span class="methodparam">void )
public void IteratorIterator::rewind ( <span class="methodparam">void )
public bool IteratorIterator::valid ( <span class="methodparam">void )
}
NoRewindIterator::__construct
Construct a NoRewindIterator
说明
public <span
class="methodname">NoRewindIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
Constructs a NoRewindIterator.
参数
iterator
The iterator being used.
返回值
A NoRewindIterator based on the passed
in iterator.
范例
示例 #1 <span class="methodname">NoRewindIterator::__construct example
The second loop does not output because the iterator is only used once, as it does not rewind.
<?php
$fruit = array('apple', 'banana', 'cranberry');
$arr = new ArrayObject($fruit);
$it = new NoRewindIterator($arr->getIterator());
echo "Fruit A:\n";
foreach( $it as $item ) {
echo $item . "\n";
}
echo "Fruit B:\n";
foreach( $it as $item ) {
echo $item . "\n";
}
?>
以上例程的输出类似于:
Fruit A:
apple
banana
cranberry
Fruit B:
参见
- NoRewindIterator::valid
NoRewindIterator::current
Get the current value
说明
public mixed NoRewindIterator::current ( <span class="methodparam">void )
Gets the current value.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current value.
参见
- NoRewindIterator::key
NoRewindIterator::getInnerIterator
Get the inner iterator
说明
public iterator NoRewindIterator::getInnerIterator ( void )
Gets the inner iterator, that was passed in to <span class="classname">NoRewindIterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The inner iterator, as passed to <span class="methodname">NoRewindIterator::__construct.
参见
- NoRewindIterator::valid
NoRewindIterator::key
Get the current key
说明
public mixed NoRewindIterator::key ( <span class="methodparam">void )
Gets the current key.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current key.
参见
- NoRewindIterator::next
NoRewindIterator::next
Forward to the next element
说明
public void NoRewindIterator::next ( <span class="methodparam">void )
Forwards to the next element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
参见
- NoRewindIterator::rewind
NoRewindIterator::rewind
Prevents the rewind operation on the inner iterator
说明
public void NoRewindIterator::rewind ( <span class="methodparam">void )
Prevents the rewind operation on the inner iterator.
参数
此函数没有参数。
返回值
没有返回值。
范例
示例 #1 NoRewindIterator::rewind example
This example demonstrates that calling rewind on a NoRewindIterator object has no effect.
<?php
$fruits = array("lemon", "orange", "apple", "pear");
$noRewindIterator = new NoRewindIterator(new ArrayIterator($fruits));
echo $noRewindIterator->current() . "\n";
$noRewindIterator->next();
// now rewind the iterator (nothing should happen)
$noRewindIterator->rewind();
echo $noRewindIterator->current() . "\n";
?>
以上例程会输出:
lemon
orange
NoRewindIterator::valid
Validates the iterator
说明
public bool NoRewindIterator::valid ( <span class="methodparam">void )
Checks whether the iterator is valid.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- NoRewindIterator::getInnerIterator
简介
This extended FilterIterator allows a recursive iteration using <span class="classname">RecursiveIteratorIterator that only shows those elements which have children.
类摘要
ParentIterator
class ParentIterator <span class="ooclass"> extends RecursiveFilterIterator implements RecursiveIterator <span class="oointerface">, OuterIterator {
/* 方法 */
public bool accept ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">RecursiveIterator
$iterator )
public <span class="type">ParentIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
/* 继承的方法 */
public Iterator OuterIterator::getInnerIterator ( <span class="methodparam">void )
}
ParentIterator::accept
Determines acceptability
说明
public bool ParentIterator::accept ( <span class="methodparam">void )
Determines if the current element has children.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the current element is acceptable, otherwise false.
参见
- ParentIterator::hasChildren
- FilterIterator::accept
ParentIterator::__construct
Constructs a ParentIterator
说明
public <span
class="methodname">ParentIterator::__construct ( <span
class="methodparam">RecursiveIterator
$iterator )
Constructs a ParentIterator on an iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The iterator being constructed upon.
返回值
The ParentIterator.
ParentIterator::getChildren
Return the inner iterator's children contained in a ParentIterator
说明
public <span class="type">ParentIterator <span class="methodname">ParentIterator::getChildren ( <span class="methodparam">void )
Get the inner iterator's children contained in a ParentIterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
An object.
ParentIterator::hasChildren
Check whether the inner iterator's current element has children
说明
public bool ParentIterator::hasChildren ( <span class="methodparam">void )
Check whether the inner iterator's current element has children.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
ParentIterator::next
Move the iterator forward
说明
public void ParentIterator::next ( <span class="methodparam">void )
Moves the iterator forward.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
ParentIterator::rewind
Rewind the iterator
说明
public void ParentIterator::rewind ( <span class="methodparam">void )
Rewinds the iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
简介
This iterator allows to unset and modify values and keys while iterating over Arrays and Objects in the same way as the <span class="type">ArrayIterator. Additionally it is possible to iterate over the current iterator entry.
类摘要
RecursiveArrayIterator
class RecursiveArrayIterator <span class="ooclass"> extends ArrayIterator implements <span class="interfacename">RecursiveIterator {
/* 继承的常量 */
const integer
STD_PROP_LIST = 1 ;
const integer
ARRAY_AS_PROPS = 2 ;
/* 常量 */
const int
CHILD_ARRAYS_ONLY = 4 ;
/* 方法 */
public <span class="type">RecursiveArrayIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
/* Inherits */
public void
ArrayIterator::append ( <span
class="methodparam">mixed $value )
public void ArrayIterator::asort ( <span class="methodparam">void )
public <span
class="methodname">ArrayIterator::__construct ([ <span
class="methodparam">mixed $array<span
class="initializer"> = array() [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
public int <span class="methodname">ArrayIterator::count ( <span class="methodparam">void )
public mixed ArrayIterator::current ( <span class="methodparam">void )
public array ArrayIterator::getArrayCopy ( <span class="methodparam">void )
public int <span class="methodname">ArrayIterator::getFlags ( <span class="methodparam">void )
public mixed ArrayIterator::key ( <span class="methodparam">void )
public void ArrayIterator::ksort ( <span class="methodparam">void )
public void ArrayIterator::natcasesort ( <span class="methodparam">void )
public void ArrayIterator::natsort ( <span class="methodparam">void )
public void ArrayIterator::next ( <span class="methodparam">void )
public bool
ArrayIterator::offsetExists ( <span
class="methodparam">mixed $index )
public mixed
ArrayIterator::offsetGet ( <span
class="methodparam">mixed $index )
public void
ArrayIterator::offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
public void
ArrayIterator::offsetUnset ( <span
class="methodparam">mixed $index )
public void ArrayIterator::rewind ( <span class="methodparam">void )
public void
ArrayIterator::seek ( <span
class="methodparam">int $position )
public string ArrayIterator::serialize ( <span class="methodparam">void )
public void
ArrayIterator::setFlags ( <span
class="methodparam">string $flags )
public void
ArrayIterator::uasort ( <span
class="methodparam">callable
$cmp_function )
public void
ArrayIterator::uksort ( <span
class="methodparam">callable
$cmp_function )
public void
ArrayIterator::unserialize ( <span
class="methodparam">string
$serialized )
public bool ArrayIterator::valid ( <span class="methodparam">void )
}
预定义常量
RecursiveArrayIterator Flags
RecursiveArrayIterator::CHILD_ARRAYS_ONLY
Treat only arrays (not objects) as having children for recursive
iteration.
更新日志
| 版本 | 说明 |
|---|---|
| 5.3.0 | CHILD_ARRAYS_ONLY flag was added. |
RecursiveArrayIterator::getChildren
Returns an iterator for the current entry if it is an <span class="type">array or an object
说明
public <span class="type">RecursiveArrayIterator <span class="methodname">RecursiveArrayIterator::getChildren ( <span class="methodparam">void )
Returns an iterator for the current iterator entry.
参数
此函数没有参数。
返回值
An iterator for the current entry, if it is an <span class="type">array or object.
错误/异常
An InvalidArgumentException will be thrown if the current entry does not contain an <span class="type">array or an object.
范例
示例 #1 <span class="function">RecursiveArrayIterator::getChildren example
<?php
$fruits = array("a" => "lemon", "b" => "orange", array("a" => "apple", "p" => "pear"));
$iterator = new RecursiveArrayIterator($fruits);
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
// print all children
foreach ($iterator->getChildren() as $key => $value) {
echo $key . ' : ' . $value . "\n";
}
} else {
echo "No children.\n";
}
$iterator->next();
}
?>
以上例程会输出:
No children.
No children.
a : apple
p : pear
参见
- RecursiveArrayIterator::hasChildren
RecursiveArrayIterator::hasChildren
Returns whether current entry is an array or an object
说明
public bool RecursiveArrayIterator::hasChildren ( void )
Returns whether current entry is an array or an object for which an iterator can be obtained via <span class="methodname">RecursiveArrayIterator::getChildren.
参数
此函数没有参数。
返回值
Returns true if the current entry is an <span
class="type">array or an object,
otherwise false is returned.
范例
示例 #1 <span class="function">RecursiveArrayIterator::hasChildren example
<?php
$fruits = array("a" => "lemon", "b" => "orange", array("a" => "apple", "p" => "pear"));
$iterator = new RecursiveArrayIterator($fruits);
while ($iterator->valid()) {
// Check if there are children
if ($iterator->hasChildren()) {
// print all children
foreach ($iterator->getChildren() as $key => $value) {
echo $key . ' : ' . $value . "\n";
}
} else {
echo "No children.\n";
}
$iterator->next();
}
?>
以上例程会输出:
No children.
No children.
a : apple
p : pear
参见
- RecursiveArrayIterator::getChildren
简介
...
类摘要
RecursiveCachingIterator
class RecursiveCachingIterator <span class="ooclass"> extends CachingIterator implements <span class="interfacename">Countable <span class="oointerface">, ArrayAccess , <span class="interfacename">OuterIterator <span class="oointerface">, <span class="interfacename">RecursiveIterator {
/* 继承的常量 */
const int
CachingIterator::CALL_TOSTRING = 1 ;
const int
CachingIterator::CATCH_GET_CHILD =
16 ;
const int
CachingIterator::TOSTRING_USE_KEY =
2 ;
const int
CachingIterator::TOSTRING_USE_CURRENT =
4 ;
const int
CachingIterator::TOSTRING_USE_INNER =
8 ;
const int
CachingIterator::FULL_CACHE = 256 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $flags =
self::CALL_TOSTRING ] )
public <span class="type">RecursiveCachingIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
/* Inherits */
public <span
class="methodname">CachingIterator::__construct ( <span
class="methodparam">Iterator
$iterator [, <span
class="type">int $flags =
self::CALL_TOSTRING ] )
public int <span class="methodname">CachingIterator::count ( <span class="methodparam">void )
public mixed CachingIterator::current ( <span class="methodparam">void )
public array CachingIterator::getCache ( <span class="methodparam">void )
public int <span class="methodname">CachingIterator::getFlags ( <span class="methodparam">void )
public Iterator CachingIterator::getInnerIterator ( void )
public void CachingIterator::hasNext ( <span class="methodparam">void )
public scalar CachingIterator::key ( <span class="methodparam">void )
public void CachingIterator::next ( <span class="methodparam">void )
public void
CachingIterator::offsetExists ( <span
class="methodparam">mixed $index )
public void
CachingIterator::offsetGet ( <span
class="methodparam">string $index )
public void
CachingIterator::offsetSet ( <span
class="methodparam">mixed $index ,
mixed
$newval )
public void
CachingIterator::offsetUnset ( <span
class="methodparam">string $index )
public void CachingIterator::rewind ( <span class="methodparam">void )
public void
CachingIterator::setFlags ( <span
class="methodparam">int $flags )
public void CachingIterator::__toString ( <span class="methodparam">void )
public void CachingIterator::valid ( <span class="methodparam">void )
}
RecursiveCachingIterator::__construct
Construct
说明
public <span
class="methodname">RecursiveCachingIterator::__construct (
Iterator
$iterator [, <span
class="type">int $flags =
self::CALL_TOSTRING ] )
Constructs a new <span
class="classname">RecursiveCachingIterator, which consists of a
passed in iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
iterator
The iterator being used.
flags
The flags. Use CALL_TOSTRING to call <span
class="methodname">RecursiveCachingIterator::__toString for
every element (the default), and/or CATCH_GET_CHILD to catch
exceptions when trying to get children.
返回值
The RecursiveCachingIterator.
参见
- CachingIterator::__construct
RecursiveCachingIterator::getChildren
Return the inner iterator's children as a RecursiveCachingIterator
说明
public <span class="type">RecursiveCachingIterator <span class="methodname">RecursiveCachingIterator::getChildren ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The inner iterator's children, as a RecursiveCachingIterator.
RecursiveCachingIterator::hasChildren
Check whether the current element of the inner iterator has children
说明
public bool RecursiveCachingIterator::hasChildren ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the inner iterator has children, otherwise false
简介
类摘要
RecursiveCallbackFilterIterator
class RecursiveCallbackFilterIterator extends CallbackFilterIterator implements OuterIterator <span class="oointerface">, <span class="interfacename">RecursiveIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">RecursiveIterator
$iterator , <span
class="type">string $callback )
public <span class="type">RecursiveCallbackFilterIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
/* 继承的方法 */
public bool CallbackFilterIterator::accept ( <span class="methodparam">void )
}
范例
The callback should accept up to three arguments: the current item, the current key and the iterator, respectively.
示例 #1 Available callback arguments
<?php
/**
* Callback for RecursiveCallbackFilterIterator
*
* @param $current Current item's value
* @param $key Current item's key
* @param $iterator Iterator being filtered
* @return boolean TRUE to accept the current item, FALSE otherwise
*/
function my_callback($current, $key, $iterator) {
// Your filtering code here
}
?>
Filtering a recursive iterator generally involves two conditions. The
first is that, to allow recursion, the callback function should return
true if the current iterator item has children. The second is the
normal filter condition, such as a file size or extension check as in
the example below.
示例 #2 Recursive callback basic example
<?php
$dir = new RecursiveDirectoryIterator(__DIR__);
// Filter large files ( > 100MB)
$files = new RecursiveCallbackFilterIterator($dir, function ($current, $key, $iterator) {
// Allow recursion
if ($iterator->hasChildren()) {
return TRUE;
}
// Check for large file
if ($current->isFile() && $current->getSize() > 104857600) {
return TRUE;
}
return FALSE;
});
foreach (new RecursiveIteratorIterator($files) as $file) {
echo $file->getPathname() . PHP_EOL;
}
?>
RecursiveCallbackFilterIterator::__construct
Create a RecursiveCallbackFilterIterator from a RecursiveIterator
说明
public <span
class="methodname">RecursiveCallbackFilterIterator::__construct
( RecursiveIterator
$iterator , <span
class="type">string $callback )
Creates a filtered iterator from a <span
class="interfacename">RecursiveIterator using the callback to
determine which items are accepted or rejected.
参数
iterator
The recursive iterator to be filtered.
callback
The callback, which should return true to accept the current item
or false otherwise. See
Examples.
May be any valid callable value.
返回值
没有返回值。
参见
- RecursiveCallbackFilterIterator Examples
- <span class="methodname">RecursiveCallbackFilterIterator::getChildren
- <span class="methodname">RecursiveCallbackFilteriterator::hasChildren
RecursiveCallbackFilterIterator::getChildren
Return the inner iterator's children contained in a RecursiveCallbackFilterIterator
说明
public <span class="type">RecursiveCallbackFilterIterator <span class="methodname">RecursiveCallbackFilterIterator::getChildren ( void )
Fetches the filtered children of the inner iterator.
<span class="methodname">RecursiveCallbackFilterIterator::hasChildren should be used to determine if there are children to be fetched.
参数
此函数没有参数。
返回值
Returns a RecursiveCallbackFilterIterator containing the children.
参见
- RecursiveCallbackFilterIterator Examples
- <span class="methodname">RecursiveCallbackFilterIterator::__construct
- <span class="methodname">RecursiveCallbackFilteriterator::hasChildren
RecursiveCallbackFilterIterator::hasChildren
Check whether the inner iterator's current element has children
说明
public bool <span class="methodname">RecursiveCallbackFilterIterator::hasChildren ( void )
Returns true if the current element has children, false
otherwise.
参数
此函数没有参数。
返回值
Returns true if the current element has children, false
otherwise.
范例
示例 #1 <span class="methodname">RecursiveCallbackFilterIterator::hasChildren basic usage
<?php
$dir = new RecursiveDirectoryIterator(__DIR__);
// Recursively iterate over XML files
$files = new RecursiveCallbackFilterIterator($dir, function ($current, $key, $iterator) {
// Allow recursion into directories
if ($iterator->hasChildren()) {
return TRUE;
}
// Check for XML file
if (!strcasecmp($current->getExtension(), 'xml')) {
return TRUE;
}
return FALSE;
});
?>
参见
- RecursiveCallbackFilterIterator Examples
- <span class="methodname">RecursiveCallbackFilterIterator::__construct
- <span class="methodname">RecursiveCallbackFilteriterator::getChildren
简介
The RecursiveDirectoryIterator provides an interface for iterating recursively over filesystem directories.
类摘要
RecursiveDirectoryIterator
class RecursiveDirectoryIterator extends FilesystemIterator implements SeekableIterator <span class="oointerface">, <span class="interfacename">RecursiveIterator {
/* 继承的常量 */
const int
FilesystemIterator::CURRENT_AS_PATHNAME =
32 ;
const int
FilesystemIterator::CURRENT_AS_FILEINFO =
0 ;
const int
FilesystemIterator::CURRENT_AS_SELF =
16 ;
const int
FilesystemIterator::CURRENT_MODE_MASK =
240 ;
const int
FilesystemIterator::KEY_AS_PATHNAME =
0 ;
const int
FilesystemIterator::KEY_AS_FILENAME =
256 ;
const int
FilesystemIterator::FOLLOW_SYMLINKS =
512 ;
const int
FilesystemIterator::KEY_MODE_MASK =
3840 ;
const int
FilesystemIterator::NEW_CURRENT_AND_KEY =
256 ;
const int
FilesystemIterator::SKIP_DOTS = 4096
;
const int
FilesystemIterator::UNIX_PATHS =
8192 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $path [,
int $flags<span
class="initializer"> = FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO ] )
public mixed getChildren ( <span class="methodparam">void )
public string getSubPath ( <span class="methodparam">void )
public string getSubPathname ( <span class="methodparam">void )
public bool
hasChildren ([ <span
class="methodparam">bool $allow_links<span
class="initializer"> = false ] )
public string key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
/* Inherits */
public <span
class="methodname">FilesystemIterator::__construct ( <span
class="methodparam">string $path [,
int $flags<span
class="initializer"> = FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS ] )
public mixed FilesystemIterator::current ( <span class="methodparam">void )
public int <span class="methodname">FilesystemIterator::getFlags ( <span class="methodparam">void )
public string FilesystemIterator::key ( <span class="methodparam">void )
public void FilesystemIterator::next ( <span class="methodparam">void )
public void FilesystemIterator::rewind ( <span class="methodparam">void )
public void
FilesystemIterator::setFlags ([ <span
class="methodparam">int $flags ] )
}
更新日志
| 版本 | 说明 |
|---|---|
| 5.3.0 | The FilesystemIterator was introduced as the parent class. Previously, the parent was the DirectoryIterator. |
| 5.3.0 | Implements SeekableIterator. |
| 5.2.11, 5.3.1 | Added RecursiveDirectoryIterator::FOLLOW_SYMLINKS |
RecursiveDirectoryIterator::__construct
Constructs a RecursiveDirectoryIterator
说明
public <span
class="methodname">RecursiveDirectoryIterator::__construct (
string
$path [, <span
class="type">int $flags =
FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO ] )
Constructs a RecursiveDirectoryIterator
for the provided path.
参数
path
The path of the directory to be iterated over.
flags
Flags may be provided which will affect the behavior of some methods. A
list of the flags can found under
FilesystemIterator predefined constants.
They can also be set later with <span
class="methodname">FilesystemIterator::setFlags.
返回值
Returns the newly created <span class="classname">RecursiveDirectoryIterator.
错误/异常
Throws an UnexpectedValueException if the
path cannot be found or is not a directory.
范例
示例 #1 RecursiveDirectoryIterator example
<?php
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
$it->rewind();
while($it->valid()) {
if (!$it->isDot()) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n";
echo 'Key: ' . $it->key() . "\n\n";
}
$it->next();
}
?>
以上例程的输出类似于:
SubPathName: fruit/apple.xml
SubPath: fruit
Key: /tmp/fruit/apple.xml
SubPathName: stuff.xml
SubPath:
Key: /tmp/stuff.xml
SubPathName: veggies/carrot.xml
SubPath: veggies
Key: /tmp/veggies/carrot.xml
参见
- FilesystemIterator::__construct
- <span class="methodname">RecursiveIteratorIterator::__construct
- FilesystemIterator predefined constants
RecursiveDirectoryIterator::getChildren
Returns an iterator for the current entry if it is a directory
说明
public mixed RecursiveDirectoryIterator::getChildren ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The filename, file information, or $this depending on the set flags. See the FilesystemIterator constants.
RecursiveDirectoryIterator::getSubPath
Get sub path
说明
public string RecursiveDirectoryIterator::getSubPath ( void )
Returns the sub path relative to the directory given in the constructor.
参数
此函数没有参数。
返回值
The sub path.
范例
示例 #1 getSubPath example
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($it as $file) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n\n";
}
以上例程的输出类似于:
SubPathName: fruit/apple.xml
SubPath: fruit
SubPathName: stuff.xml
SubPath:
SubPathName: veggies/carrot.xml
SubPath: veggies
参见
- <span class="methodname">RecursiveDirectoryIterator::getSubPathName
- RecursiveDirectoryIterator::key
RecursiveDirectoryIterator::getSubPathname
Get sub path and name
说明
public string <span class="methodname">RecursiveDirectoryIterator::getSubPathname ( void )
Gets the sub path and filename.
参数
此函数没有参数。
返回值
The sub path (sub directory) and filename.
范例
示例 #1 getSubPathname example
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($it as $file) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n\n";
}
以上例程的输出类似于:
SubPathName: fruit/apple.xml
SubPath: fruit
SubPathName: stuff.xml
SubPath:
SubPathName: veggies/carrot.xml
SubPath: veggies
参见
- <span class="methodname">RecursiveDirectoryIterator::getSubPath
- RecursiveDirectoryIterator::key
RecursiveDirectoryIterator::hasChildren
Returns whether current entry is a directory and not '.' or '..'
说明
public bool
RecursiveDirectoryIterator::hasChildren
([ bool
$allow_links = false ]
)
Warning
本函数还未编写文档,仅有参数列表。
参数
allow_links
返回值
Returns whether the current entry is a directory, but not '.' or '..'
RecursiveDirectoryIterator::key
Return path and filename of current dir entry
说明
public string RecursiveDirectoryIterator::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The path and filename of the current dir entry.
RecursiveDirectoryIterator::next
Move to next entry
说明
public void RecursiveDirectoryIterator::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveDirectoryIterator::rewind
Rewind dir back to the start
说明
public void RecursiveDirectoryIterator::rewind ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
简介
This abstract iterator filters out unwanted values for a <span class="classname">RecursiveIterator. This class should be extended to implement custom filters. The <span class="methodname">RecursiveFilterIterator::accept must be implemented in the subclass.
类摘要
RecursiveFilterIterator
abstract class RecursiveFilterIterator <span class="modifier">extends FilterIterator <span class="oointerface">implements <span class="interfacename">OuterIterator <span class="oointerface">, <span class="interfacename">RecursiveIterator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">RecursiveIterator
$iterator )
public <span class="type">RecursiveFilterIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
/* 继承的方法 */
public <span class="modifier">abstract bool <span class="methodname">FilterIterator::accept ( <span class="methodparam">void )
public <span
class="methodname">FilterIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
public mixed FilterIterator::current ( <span class="methodparam">void )
public Iterator FilterIterator::getInnerIterator ( <span class="methodparam">void )
public mixed FilterIterator::key ( <span class="methodparam">void )
public void FilterIterator::next ( <span class="methodparam">void )
public void FilterIterator::rewind ( <span class="methodparam">void )
public bool FilterIterator::valid ( <span class="methodparam">void )
}
RecursiveFilterIterator::__construct
Create a RecursiveFilterIterator from a RecursiveIterator
说明
public <span
class="methodname">RecursiveFilterIterator::__construct ( <span
class="methodparam">RecursiveIterator
$iterator )
Create a RecursiveFilterIterator from a RecursiveIterator.
参数
iterator
The RecursiveIterator to be filtered.
返回值
没有返回值。
范例
示例 #1 Basic RecursiveFilterIterator example
<?php
class TestsOnlyFilter extends RecursiveFilterIterator {
public function accept() {
// Accept the current item if we can recurse into it
// or it is a value starting with "test"
return $this->hasChildren() || (strpos($this->current(), "test") !== FALSE);
}
}
$array = array("test1", array("taste2", "test3", "test4"), "test5");
$iterator = new RecursiveArrayIterator($array);
$filter = new TestsOnlyFilter($iterator);
foreach(new RecursiveIteratorIterator($filter) as $key => $value)
{
echo $value . "\n";
}
?>
以上例程的输出类似于:
test1
test3
test4
test5
示例 #2 RecursiveFilterIterator example
<?php
class StartsWithFilter extends RecursiveFilterIterator {
protected $word;
public function __construct(RecursiveIterator $rit, $word) {
$this->word = $word;
parent::__construct($rit);
}
public function accept() {
return $this->hasChildren() OR strpos($this->current(), $this->word) === 0;
}
public function getChildren() {
return new self($this->getInnerIterator()->getChildren(), $this->word);
}
}
$array = array("test1", array("taste2", "test3", "test4"), "test5");
$iterator = new RecursiveArrayIterator($array);
$filter = new StartsWithFilter($iterator, "test");
foreach(new RecursiveIteratorIterator($filter) as $key => $value)
{
echo $value . "\n";
}
?>
以上例程的输出类似于:
test1
test3
test4
test5
参见
- RecursiveFilterIterator::getChildren
- RecursiveFilterIterator::hasChildren
- FilterIterator::accept
RecursiveFilterIterator::getChildren
Return the inner iterator's children contained in a RecursiveFilterIterator
说明
public <span class="type">RecursiveFilterIterator <span class="methodname">RecursiveFilterIterator::getChildren ( <span class="methodparam">void )
Return the inner iterator's children contained in a <span class="classname">RecursiveFilterIterator.
参数
此函数没有参数。
返回值
Returns a RecursiveFilterIterator containing the inner iterator's children.
参见
- RecursiveFilterIterator::hasChildren
- RecursiveIterator::getChildren
RecursiveFilterIterator::hasChildren
Check whether the inner iterator's current element has children
说明
public bool RecursiveFilterIterator::hasChildren ( void )
Check whether the inner iterator's current element has children.
参数
此函数没有参数。
返回值
true if the inner iterator has children, otherwise false
参见
- RecursiveFilterIterator::getChildren
- RecursiveIterator::hasChildren
简介
Can be used to iterate through recursive iterators.
类摘要
RecursiveIteratorIterator
class RecursiveIteratorIterator <span class="oointerface">implements <span class="interfacename">OuterIterator {
/* 常量 */
const int
RecursiveIteratorIterator::LEAVES_ONLY =
0 ;
const int
RecursiveIteratorIterator::SELF_FIRST =
1 ;
const int
RecursiveIteratorIterator::CHILD_FIRST =
2 ;
const int
RecursiveIteratorIterator::CATCH_GET_CHILD
= 16 ;
/* 方法 */
public void beginChildren ( <span class="methodparam">void )
public void beginIteration ( <span class="methodparam">void )
public <span class="type">RecursiveIterator <span class="methodname">callGetChildren ( <span class="methodparam">void )
public bool callHasChildren ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">Traversable
$iterator [, <span
class="type">int $mode =
RecursiveIteratorIterator::LEAVES_ONLY [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
public mixed current ( <span class="methodparam">void )
public void endChildren ( <span class="methodparam">void )
public void endIteration ( <span class="methodparam">void )
public int <span class="methodname">getDepth ( <span class="methodparam">void )
public iterator getInnerIterator ( <span class="methodparam">void )
public mixed getMaxDepth ( <span class="methodparam">void )
public <span
class="type">RecursiveIterator <span
class="methodname">getSubIterator ([ <span
class="methodparam">int $level ] )
public mixed key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void nextElement ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
setMaxDepth ([ <span
class="methodparam">int $max_depth<span
class="initializer"> = -1 ] )
public bool valid ( <span class="methodparam">void )
/* 继承的方法 */
public Iterator OuterIterator::getInnerIterator ( <span class="methodparam">void )
}
预定义常量
RecursiveIteratorIterator::LEAVES_ONLY
RecursiveIteratorIterator::SELF_FIRST
RecursiveIteratorIterator::CHILD_FIRST
RecursiveIteratorIterator::CATCH_GET_CHILD
RecursiveIteratorIterator::beginChildren
Begin children
说明
public void RecursiveIteratorIterator::beginChildren ( void )
Is called after calling <span class="methodname">RecursiveIteratorIterator::getChildren, and its associated <span class="methodname">RecursiveIteratorIterator::rewind.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::beginIteration
Begin Iteration
说明
public void <span class="methodname">RecursiveIteratorIterator::beginIteration ( void )
Called when iteration begins (after the first <span class="methodname">RecursiveIteratorIterator::rewind call.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::callGetChildren
Get children
说明
public <span class="type">RecursiveIterator <span class="methodname">RecursiveIteratorIterator::callGetChildren ( void )
Get children of the current element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A RecursiveIterator.
RecursiveIteratorIterator::callHasChildren
Has children
说明
public bool <span class="methodname">RecursiveIteratorIterator::callHasChildren ( void )
Called for each element to test whether it has children.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the element has children, otherwise false
RecursiveIteratorIterator::__construct
Construct a RecursiveIteratorIterator
说明
public <span
class="methodname">RecursiveIteratorIterator::__construct (
Traversable
$iterator [, <span
class="type">int $mode =
RecursiveIteratorIterator::LEAVES_ONLY [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
Creates a RecursiveIteratorIterator from a RecursiveIterator.
参数
iterator
The iterator being constructed from. Either a <span
class="classname">RecursiveIterator or <span
class="classname">IteratorAggregate.
mode
Optional mode. Possible values are
RecursiveIteratorIterator::LEAVES_ONLY- The default. Lists only leaves in iteration.RecursiveIteratorIterator::SELF_FIRST- Lists leaves and parents in iteration with parents coming first.RecursiveIteratorIterator::CHILD_FIRST- Lists leaves and parents in iteration with leaves coming first.
flags
Optional flag. Possible values are
RecursiveIteratorIterator::CATCH_GET_CHILD which will then ignore
exceptions thrown in calls to <span
class="methodname">RecursiveIteratorIterator::getChildren.
返回值
没有返回值。
范例
示例 #1 Iterating a RecursiveIteratorIterator
<?php
$array = array(
array(
array(
array(
'leaf-0-0-0-0',
'leaf-0-0-0-1'
),
'leaf-0-0-0'
),
array(
array(
'leaf-0-1-0-0',
'leaf-0-1-0-1'
),
'leaf-0-1-0'
),
'leaf-0-0'
)
);
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($array),
$mode
);
foreach ($iterator as $key => $leaf) {
echo "$key => $leaf", PHP_EOL;
}
?>
Output with $mode = RecursiveIteratorIterator::LEAVES_ONLY
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
0 => leaf-0-0-0
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
0 => leaf-0-1-0
0 => leaf-0-0
Output with $mode = RecursiveIteratorIterator::SELF_FIRST
0 => Array
0 => Array
0 => Array
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
1 => leaf-0-0-0
1 => Array
0 => Array
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
1 => leaf-0-1-0
2 => leaf-0-0
Output with $mode = RecursiveIteratorIterator::CHILD_FIRST
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
0 => Array
1 => leaf-0-0-0
0 => Array
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
0 => Array
1 => leaf-0-1-0
1 => Array
2 => leaf-0-0
0 => Array
RecursiveIteratorIterator::current
Access the current element value
说明
public mixed RecursiveIteratorIterator::current ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current elements value.
RecursiveIteratorIterator::endChildren
End children
说明
public void RecursiveIteratorIterator::endChildren ( void )
Called when end recursing one level.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::endIteration
End Iteration
说明
public void RecursiveIteratorIterator::endIteration ( void )
Called when the iteration ends (when <span
class="methodname">RecursiveIteratorIterator::valid first returns
false.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::getDepth
Get the current depth of the recursive iteration
说明
public int <span class="methodname">RecursiveIteratorIterator::getDepth ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current depth of the recursive iteration.
RecursiveIteratorIterator::getInnerIterator
Get inner iterator
说明
public iterator <span class="methodname">RecursiveIteratorIterator::getInnerIterator ( void )
Gets the current active sub iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current active sub iterator.
RecursiveIteratorIterator::getMaxDepth
Get max depth
说明
public mixed RecursiveIteratorIterator::getMaxDepth ( void )
Gets the maximum allowable depth.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The maximum accepted depth, or false if any depth is allowed.
参见
- <span class="methodname">RecursiveIteratorIterator::setMaxDepth
RecursiveIteratorIterator::getSubIterator
The current active sub iterator
说明
public <span
class="type">RecursiveIterator <span
class="methodname">RecursiveIteratorIterator::getSubIterator ([
int $level
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
level
返回值
The current active sub iterator.
RecursiveIteratorIterator::key
Access the current key
说明
public mixed RecursiveIteratorIterator::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The current key.
RecursiveIteratorIterator::next
Move forward to the next element
说明
public void RecursiveIteratorIterator::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::nextElement
Next element
说明
public void RecursiveIteratorIterator::nextElement ( void )
Called when the next element is available.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::rewind
Rewind the iterator to the first element of the top level inner iterator
说明
public void RecursiveIteratorIterator::rewind ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveIteratorIterator::setMaxDepth
Set max depth
说明
public void
RecursiveIteratorIterator::setMaxDepth
([ int
$max_depth = -1 ] )
Set the maximum allowed depth.
Warning
本函数还未编写文档,仅有参数列表。
参数
max_depth
The maximum allowed depth. -1 is used for any depth.
返回值
没有返回值。
错误/异常
Emits an Exception if max_depth is less
than -1.
RecursiveIteratorIterator::valid
Check whether the current position is valid
说明
public bool RecursiveIteratorIterator::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the current position is valid, otherwise false
简介
This recursive iterator can filter another recursive iterator via a regular expression.
类摘要
RecursiveRegexIterator
class RecursiveRegexIterator <span class="ooclass"> extends RegexIterator implements <span class="interfacename">RecursiveIterator {
/* 继承的常量 */
const int
MATCH = 0 ;
const int
GET_MATCH = 1 ;
const int
ALL_MATCHES = 2 ;
const int
SPLIT = 3 ;
const int
REPLACE = 4 ;
const int
USE_KEY = 1 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">RecursiveIterator
$iterator , <span
class="type">string $regex [, <span
class="methodparam">int $mode<span
class="initializer"> = self::MATCH [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 [, <span
class="methodparam">int $preg_flags<span
class="initializer"> = 0 ]]] )
public <span class="type">RecursiveRegexIterator <span class="methodname">getChildren ( <span class="methodparam">void )
public bool hasChildren ( <span class="methodparam">void )
/* 继承的方法 */
public <span class="type">RecursiveIterator <span class="methodname">RecursiveIterator::getChildren ( <span class="methodparam">void )
public bool RecursiveIterator::hasChildren ( <span class="methodparam">void )
public bool RegexIterator::accept ( <span class="methodparam">void )
public int <span class="methodname">RegexIterator::getFlags ( <span class="methodparam">void )
public int <span class="methodname">RegexIterator::getMode ( <span class="methodparam">void )
public int <span class="methodname">RegexIterator::getPregFlags ( <span class="methodparam">void )
public string RegexIterator::getRegex ( <span class="methodparam">void )
public void
RegexIterator::setFlags ( <span
class="methodparam">int $flags )
public void
RegexIterator::setMode ( <span
class="methodparam">int $mode )
public void
RegexIterator::setPregFlags ( <span
class="methodparam">int $preg_flags )
}
RecursiveRegexIterator::__construct
Creates a new RecursiveRegexIterator
说明
public <span
class="methodname">RecursiveRegexIterator::__construct ( <span
class="methodparam">RecursiveIterator
$iterator , <span
class="type">string $regex [, <span
class="methodparam">int $mode<span
class="initializer"> = self::MATCH [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 [, <span
class="methodparam">int $preg_flags<span
class="initializer"> = 0 ]]] )
Creates a new regular expression iterator.
参数
iterator
The recursive iterator to apply this regex filter to.
regex
The regular expression to match.
mode
Operation mode, see <span
class="methodname">RegexIterator::setMode for a list of modes.
flags
Special flags, see <span
class="methodname">RegexIterator::setFlags for a list of
available flags.
preg_flags
The regular expression flags. These flags depend on the operation mode
parameter:
| operation mode | available flags |
|---|---|
RecursiveRegexIterator::ALL_MATCHES |
See preg_match_all. |
RecursiveRegexIterator::GET_MATCH |
See preg_match. |
RecursiveRegexIterator::MATCH |
See preg_match. |
RecursiveRegexIterator::REPLACE |
none. |
RecursiveRegexIterator::SPLIT |
See preg_split. |
范例
示例 #1 <span class="function">RecursiveRegexIterator::__construct example
Creates a new RegexIterator that filters all strings that start with 'test'.
<?php
$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^test/',
RecursiveRegexIterator::ALL_MATCHES);
foreach ($rRegexIterator as $key1 => $value1) {
if ($rRegexIterator->hasChildren()) {
// print all children
echo "Children: ";
foreach ($rRegexIterator->getChildren() as $key => $value) {
echo $value . " ";
}
echo "\n";
} else {
echo "No children\n";
}
}
?>
以上例程的输出类似于:
No children
Children: test4 test5
参见
- preg_match
- preg_match_all
- preg_replace
- preg_split
RecursiveRegexIterator::getChildren
Returns an iterator for the current entry
说明
public <span class="type">RecursiveRegexIterator <span class="methodname">RecursiveRegexIterator::getChildren ( <span class="methodparam">void )
Returns an iterator for the current iterator entry.
参数
此函数没有参数。
返回值
An iterator for the current entry, if it can be iterated over by the inner iterator.
错误/异常
An InvalidArgumentException will be thrown if the current entry does not contain a value that can be iterated over by the inner iterator.
范例
示例 #1 <span class="function">RecursiveRegexIterator::getChildren example
<?php
$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^test/',
RecursiveRegexIterator::ALL_MATCHES);
foreach ($rRegexIterator as $key1 => $value1) {
if ($rRegexIterator->hasChildren()) {
// print all children
echo "Children: ";
foreach ($rRegexIterator->getChildren() as $key => $value) {
echo $value . " ";
}
echo "\n";
} else {
echo "No children\n";
}
}
?>
以上例程会输出:
No children
Children: test4 test5
参见
- RecursiveRegexIterator::hasChildren
RecursiveRegexIterator::hasChildren
Returns whether an iterator can be obtained for the current entry
说明
public bool RecursiveRegexIterator::hasChildren ( void )
Returns whether an iterator can be obtained for the current entry. This iterator can be obtained via <span class="methodname">RecursiveRegexIterator::getChildren.
参数
此函数没有参数。
返回值
Returns true if an iterator can be obtained for the current entry,
otherwise returns false.
范例
示例 #1 <span class="function">RecursiveRegexIterator::hasChildren example
<?php
$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^test/',
RecursiveRegexIterator::ALL_MATCHES);
foreach ($rRegexIterator as $value) {
var_dump($rRegexIterator->hasChildren());
}
?>
以上例程会输出:
bool(false)
bool(true)
参见
- RecursiveRegexIterator::getChildren
简介
Allows iterating over a RecursiveIterator to generate an ASCII graphic tree.
类摘要
RecursiveTreeIterator
class RecursiveTreeIterator <span class="ooclass"> extends RecursiveIteratorIterator <span class="oointerface">implements <span class="interfacename">OuterIterator {
/* 继承的常量 */
const int
RecursiveIteratorIterator::LEAVES_ONLY =
0 ;
const int
RecursiveIteratorIterator::SELF_FIRST =
1 ;
const int
RecursiveIteratorIterator::CHILD_FIRST =
2 ;
const int
RecursiveIteratorIterator::CATCH_GET_CHILD
= 16 ;
/* 常量 */
const int
RecursiveTreeIterator::BYPASS_CURRENT =
4 ;
const int
RecursiveTreeIterator::BYPASS_KEY =
8 ;
const int
RecursiveTreeIterator::PREFIX_LEFT =
0 ;
const int
RecursiveTreeIterator::PREFIX_MID_HAS_NEXT
= 1 ;
const int
RecursiveTreeIterator::PREFIX_MID_LAST =
2 ;
const int
RecursiveTreeIterator::PREFIX_END_HAS_NEXT
= 3 ;
const int
RecursiveTreeIterator::PREFIX_END_LAST =
4 ;
const int
RecursiveTreeIterator::PREFIX_RIGHT =
5 ;
/* 方法 */
public void beginChildren ( <span class="methodparam">void )
public <span class="type">RecursiveIterator <span class="methodname">beginIteration ( <span class="methodparam">void )
public <span class="type">RecursiveIterator <span class="methodname">callGetChildren ( <span class="methodparam">void )
public bool callHasChildren ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam"><span
class="type">RecursiveIterator<span
class="type">IteratorAggregate $it [, <span
class="methodparam">int $flags<span
class="initializer"> = RecursiveTreeIterator::BYPASS_KEY
[, int
$cit_flags =
CachingIterator::CATCH_GET_CHILD [, <span
class="methodparam">int $mode<span
class="initializer"> =
RecursiveIteratorIterator::SELF_FIRST ]]] )
public string current ( <span class="methodparam">void )
public void endChildren ( <span class="methodparam">void )
public void endIteration ( <span class="methodparam">void )
public string getEntry ( <span class="methodparam">void )
public string getPostfix ( <span class="methodparam">void )
public string getPrefix ( <span class="methodparam">void )
public string key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void nextElement ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
setPostfix ( <span
class="methodparam">string $postfix )
public void
setPrefixPart ( <span
class="methodparam">int $part , <span
class="methodparam">string $value )
public bool valid ( <span class="methodparam">void )
/* 继承的方法 */
public void RecursiveIteratorIterator::beginChildren ( void )
public void <span class="methodname">RecursiveIteratorIterator::beginIteration ( void )
public <span class="type">RecursiveIterator <span class="methodname">RecursiveIteratorIterator::callGetChildren ( void )
public bool <span class="methodname">RecursiveIteratorIterator::callHasChildren ( void )
public <span
class="methodname">RecursiveIteratorIterator::__construct (
Traversable
$iterator [, <span
class="type">int $mode =
RecursiveIteratorIterator::LEAVES_ONLY [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 ]] )
public mixed RecursiveIteratorIterator::current ( void )
public void RecursiveIteratorIterator::endChildren ( void )
public void RecursiveIteratorIterator::endIteration ( void )
public int <span class="methodname">RecursiveIteratorIterator::getDepth ( <span class="methodparam">void )
public iterator <span class="methodname">RecursiveIteratorIterator::getInnerIterator ( void )
public mixed RecursiveIteratorIterator::getMaxDepth ( void )
public <span
class="type">RecursiveIterator <span
class="methodname">RecursiveIteratorIterator::getSubIterator ([
int $level
] )
public mixed RecursiveIteratorIterator::key ( <span class="methodparam">void )
public void RecursiveIteratorIterator::next ( <span class="methodparam">void )
public void RecursiveIteratorIterator::nextElement ( void )
public void RecursiveIteratorIterator::rewind ( void )
public void
RecursiveIteratorIterator::setMaxDepth
([ int
$max_depth = -1 ] )
public bool RecursiveIteratorIterator::valid ( <span class="methodparam">void )
}
预定义常量
RecursiveTreeIterator::BYPASS_CURRENT
RecursiveTreeIterator::BYPASS_KEY
RecursiveTreeIterator::PREFIX_LEFT
RecursiveTreeIterator::PREFIX_MID_HAS_NEXT
RecursiveTreeIterator::PREFIX_MID_LAST
RecursiveTreeIterator::PREFIX_END_HAS_NEXT
RecursiveTreeIterator::PREFIX_END_LAST
RecursiveTreeIterator::PREFIX_RIGHT
RecursiveTreeIterator::beginChildren
Begin children
说明
public void RecursiveTreeIterator::beginChildren ( void )
Called when recursing one level down.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::beginIteration
Begin iteration
说明
public <span class="type">RecursiveIterator <span class="methodname">RecursiveTreeIterator::beginIteration ( <span class="methodparam">void )
Called when iteration begins (after the first <span class="methodname">RecursiveTreeIterator::rewind call).
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A RecursiveIterator.
RecursiveTreeIterator::callGetChildren
Get children
说明
public <span class="type">RecursiveIterator <span class="methodname">RecursiveTreeIterator::callGetChildren ( <span class="methodparam">void )
Gets children of the current element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A RecursiveIterator.
RecursiveTreeIterator::callHasChildren
Has children
说明
public bool RecursiveTreeIterator::callHasChildren ( void )
Called for each element to test whether it has children.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if there are children, otherwise false
RecursiveTreeIterator::__construct
Construct a RecursiveTreeIterator
说明
public <span
class="methodname">RecursiveTreeIterator::__construct ( <span
class="methodparam"><span
class="type">RecursiveIterator<span
class="type">IteratorAggregate $it [, <span
class="methodparam">int $flags<span
class="initializer"> = RecursiveTreeIterator::BYPASS_KEY
[, int
$cit_flags =
CachingIterator::CATCH_GET_CHILD [, <span
class="methodparam">int $mode<span
class="initializer"> =
RecursiveIteratorIterator::SELF_FIRST ]]] )
Constructs a new RecursiveTreeIterator from the supplied recursive iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
it
The RecursiveIterator or <span
class="classname">IteratorAggregate to iterate over.
flags
Flags may be provided which will affect the behavior of some methods. A
list of the flags can found under
RecursiveTreeIterator predefined constants.
caching_it_flags
Flags to affect the behavior of the <span
class="classname">RecursiveCachingIterator used internally.
mode
Flags to affect the behavior of the <span
class="classname">RecursiveIteratorIterator used internally.
返回值
没有返回值。
RecursiveTreeIterator::current
Get current element
说明
public string RecursiveTreeIterator::current ( <span class="methodparam">void )
Gets the current element prefixed and postfixed.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the current element prefixed and postfixed.
RecursiveTreeIterator::endChildren
End children
说明
public void RecursiveTreeIterator::endChildren ( void )
Called when end recursing one level.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::endIteration
End iteration
说明
public void RecursiveTreeIterator::endIteration ( void )
Called when the iteration ends (when <span
class="methodname">RecursiveTreeIterator::valid first returns
false)
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::getEntry
Get current entry
说明
public string RecursiveTreeIterator::getEntry ( <span class="methodparam">void )
Gets the part of the tree built for the current element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the part of the tree built for the current element.
RecursiveTreeIterator::getPostfix
Get the postfix
说明
public string RecursiveTreeIterator::getPostfix ( void )
Gets the string to place after the current element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the string to place after the current element.
RecursiveTreeIterator::getPrefix
Get the prefix
说明
public string RecursiveTreeIterator::getPrefix ( <span class="methodparam">void )
Gets the string to place in front of current element
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the string to place in front of current element
RecursiveTreeIterator::key
Get the key of the current element
说明
public string RecursiveTreeIterator::key ( <span class="methodparam">void )
Gets the current key prefixed and postfixed.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the current key prefixed and postfixed.
RecursiveTreeIterator::next
Move to next element
说明
public void RecursiveTreeIterator::next ( <span class="methodparam">void )
Moves forward to the next element.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::nextElement
Next element
说明
public void RecursiveTreeIterator::nextElement ( void )
Called when the next element is available.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::rewind
Rewind iterator
说明
public void RecursiveTreeIterator::rewind ( <span class="methodparam">void )
Rewinds the iterator to the first element of the top level inner iterator.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
没有返回值。
RecursiveTreeIterator::setPostfix
Set postfix
说明
public void
RecursiveTreeIterator::setPostfix (
string
$postfix )
Sets postfix as used in <span class="methodname">RecursiveTreeIterator::getPostfix.
Warning
本函数还未编写文档,仅有参数列表。
参数
postfix
返回值
没有返回值。
RecursiveTreeIterator::setPrefixPart
Set a part of the prefix
说明
public void
RecursiveTreeIterator::setPrefixPart (
int $part ,
string
$value )
Sets a part of the prefix used in the graphic tree.
Warning
本函数还未编写文档,仅有参数列表。
参数
part
One of the
RecursiveTreeIterator::PREFIX_*
constants.
value
The value to assign to the part of the prefix specified in part.
返回值
没有返回值。
RecursiveTreeIterator::valid
Check validity
说明
public bool RecursiveTreeIterator::valid ( <span class="methodparam">void )
Check whether the current position is valid.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the current position is valid, otherwise false
简介
This iterator can be used to filter another iterator based on a regular expression.
类摘要
RegexIterator
class RegexIterator <span class="ooclass"> extends FilterIterator {
/* 常量 */
const int
MATCH = 0 ;
const int
GET_MATCH = 1 ;
const int
ALL_MATCHES = 2 ;
const int
SPLIT = 3 ;
const int
REPLACE = 4 ;
const int
USE_KEY = 1 ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Iterator
$iterator , <span
class="type">string $regex [, <span
class="methodparam">int $mode<span
class="initializer"> = self::MATCH [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 [, <span
class="methodparam">int $preg_flags<span
class="initializer"> = 0 ]]] )
public bool accept ( <span class="methodparam">void )
public int <span class="methodname">getFlags ( <span class="methodparam">void )
public int <span class="methodname">getMode ( <span class="methodparam">void )
public int <span class="methodname">getPregFlags ( <span class="methodparam">void )
public string getRegex ( <span class="methodparam">void )
public void
setFlags ( <span
class="methodparam">int $flags )
public void
setMode ( <span
class="methodparam">int $mode )
public void
setPregFlags ( <span
class="methodparam">int $preg_flags )
/* 继承的方法 */
public <span class="modifier">abstract bool <span class="methodname">FilterIterator::accept ( <span class="methodparam">void )
public <span
class="methodname">FilterIterator::__construct ( <span
class="methodparam">Iterator
$iterator )
public mixed FilterIterator::current ( <span class="methodparam">void )
public Iterator FilterIterator::getInnerIterator ( <span class="methodparam">void )
public mixed FilterIterator::key ( <span class="methodparam">void )
public void FilterIterator::next ( <span class="methodparam">void )
public void FilterIterator::rewind ( <span class="methodparam">void )
public bool FilterIterator::valid ( <span class="methodparam">void )
}
预定义常量
RegexIterator operation modes
RegexIterator::ALL_MATCHES
Return all matches for the current entry (see <span
class="function">preg_match_all).
RegexIterator::GET_MATCH
Return the first match for the current entry (see <span
class="function">preg_match).
RegexIterator::MATCH
Only execute match (filter) for the current entry (see <span
class="function">preg_match).
RegexIterator::REPLACE
Replace the current entry (see <span
class="function">preg_replace; Not fully implemented yet)
RegexIterator::SPLIT
Returns the split values for the current entry (see <span
class="function">preg_split).
RegexIterator Flags
RegexIterator::USE_KEY
Special flag: Match the entry key instead of the entry value.
RegexIterator::accept
Get accept status
说明
public bool RegexIterator::accept ( <span class="methodparam">void )
Matches (string) <span class="methodname">RegexIterator::current (or <span class="methodname">RegexIterator::key if the RegexIterator::USE_KEY flag is set) against the regular expression.
参数
此函数没有参数。
返回值
true if a match, false otherwise.
范例
示例 #1 RegexIterator::accept example
This example shows that only items matching the regular expression are accepted.
<?php
$names = new ArrayIterator(array('Ann', 'Bob', 'Charlie', 'David'));
$filter = new RegexIterator($names, '/^[B-D]/');
foreach ($filter as $name) {
echo $name . PHP_EOL;
}
?>
以上例程会输出:
Bob
Charlie
David
参见
- RegexIterator constants
- RegexIterator::setFlags
RegexIterator::__construct
Create a new RegexIterator
说明
public <span
class="methodname">RegexIterator::__construct ( <span
class="methodparam">Iterator
$iterator , <span
class="type">string $regex [, <span
class="methodparam">int $mode<span
class="initializer"> = self::MATCH [, <span
class="methodparam">int $flags<span
class="initializer"> = 0 [, <span
class="methodparam">int $preg_flags<span
class="initializer"> = 0 ]]] )
Create a new RegexIterator which filters an Iterator using a regular expression.
参数
iterator
The iterator to apply this regex filter to.
regex
The regular expression to match.
mode
Operation mode, see <span
class="methodname">RegexIterator::setMode for a list of modes.
flags
Special flags, see <span
class="methodname">RegexIterator::setFlags for a list of
available flags.
preg_flags
The regular expression flags. These flags depend on the operation mode
parameter:
| operation mode | available flags |
|---|---|
RegexIterator::ALL_MATCHES |
See preg_match_all. |
RegexIterator::GET_MATCH |
See preg_match. |
RegexIterator::MATCH |
See preg_match. |
RegexIterator::REPLACE |
none. |
RegexIterator::SPLIT |
See preg_split. |
错误/异常
Throws an InvalidArgumentException if the
regex argument is invalid.
范例
示例 #1 RegexIterator::__construct example
Creates a new RegexIterator that filters all strings that start with 'test'.
<?php
$arrayIterator = new ArrayIterator(array('test 1', 'another test', 'test 123'));
$regexIterator = new RegexIterator($arrayIterator, '/^test/');
foreach ($regexIterator as $value) {
echo $value . "\n";
}
?>
以上例程的输出类似于:
test 1
test 123
参见
- preg_match
- preg_match_all
- preg_replace
- preg_split
RegexIterator::getFlags
Get flags
说明
public int <span class="methodname">RegexIterator::getFlags ( <span class="methodparam">void )
Returns the flags, see <span class="methodname">RegexIterator::setFlags for a list of available flags.
返回值
Returns the set flags.
范例
示例 #1 RegexIterator::getFlags example
<?php
$test = array ('str1' => 'test 1', 'teststr2' => 'another test', 'str3' => 'test 123');
$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/^test/');
$regexIterator->setFlags(RegexIterator::USE_KEY);
if ($regexIterator->getFlags() & RegexIterator::USE_KEY) {
echo 'Filtering based on the array keys.';
} else {
echo 'Filtering based on the array values.';
}
?>
以上例程会输出:
Filtering based on the array keys.
参见
- RegexIterator::setFlags
RegexIterator::getMode
Returns operation mode
说明
public int <span class="methodname">RegexIterator::getMode ( <span class="methodparam">void )
Returns the operation mode, see <span class="methodname">RegexIterator::setMode for the list of operation modes.
返回值
Returns the operation mode.
范例
示例 #1 RegexIterator::getMode example
<?php
$test = array ('str1' => 'test 1', 'teststr2' => 'another test', 'str3' => 'test 123');
$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/^[a-z]+/', RegexIterator::GET_MATCH);
$mode = $regexIterator->getMode();
if ($mode & RegexIterator::GET_MATCH) {
echo 'Getting the match for each item.';
} elseif ($mode & RegexIterator::ALL_MATCHES) {
echo 'Getting all matches for each item.';
} elseif ($mode & RegexIterator::MATCH) {
echo 'Getting each item if it matches.';
} elseif ($mode & RegexIterator::SPLIT) {
echo 'Getting split pieces of each.';
}
?>
以上例程会输出:
Getting the match for each item.
参见
- RegexIterator::setMode
RegexIterator::getPregFlags
Returns the regular expression flags
说明
public int <span class="methodname">RegexIterator::getPregFlags ( <span class="methodparam">void )
Returns the regular expression flags, see <span class="methodname">RegexIterator::__construct for the list of flags.
返回值
Returns a bitmask of the regular expression flags.
范例
示例 #1 RegexIterator::getPregFlags example
<?php
$test = array ('str1' => 'test 1', 'teststr2' => 'another test', 'str3' => 'test 123');
$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/\s/', RegexIterator::SPLIT);
$regexIterator->setPregFlags(PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
if ($regexIterator->getPregFlags() & PREG_SPLIT_NO_EMPTY) {
echo 'Ignoring empty pieces';
} else {
echo 'Not ignoring empty pieces';
}
?>
以上例程会输出:
Ignoring empty pieces
参见
- RegexIterator::setPregFlags
RegexIterator::getRegex
Returns current regular expression
说明
public string RegexIterator::getRegex ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
RegexIterator::setFlags
Sets the flags
说明
public void
RegexIterator::setFlags ( <span
class="methodparam">int $flags )
Sets the flags.
参数
flags
The flags to set, a bitmask of class constants.
The available flags are listed below. The actual meanings of these flags are described in the predefined constants.
| value | constant |
|---|---|
| 1 | RegexIterator::USE_KEY |
返回值
没有返回值。
范例
示例 #1 RegexIterator::setFlags example
Creates a new RegexIterator that filters all entries whose key starts with 'test'.
<?php
$test = array ('str1' => 'test 1', 'teststr2' => 'another test', 'str3' => 'test 123');
$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/^test/');
$regexIterator->setFlags(RegexIterator::USE_KEY);
foreach ($regexIterator as $key => $value) {
echo $key . ' => ' . $value . "\n";
}
?>
以上例程会输出:
teststr2 => another test
参见
- RegexIterator::getFlags
RegexIterator::setMode
Sets the operation mode
说明
public void
RegexIterator::setMode ( <span
class="methodparam">int $mode )
Sets the operation mode.
参数
mode
The operation mode.
The available modes are listed below. The actual meanings of these modes are described in the predefined constants.
| value | constant |
|---|---|
| 0 | RegexIterator::MATCH |
| 1 | RegexIterator::GET_MATCH |
| 2 | RegexIterator::ALL_MATCHES |
| 3 | RegexIterator::SPLIT |
| 4 | RegexIterator::REPLACE |
返回值
没有返回值。
范例
示例 #1 RegexIterator::setMode example
<?php
$test = array ('str1' => 'test 1', 'test str2' => 'another test', 'str3' => 'test 123');
$arrayIterator = new ArrayIterator($test);
// Filter everything that starts with 'test ' followed by one or more numbers.
$regexIterator = new RegexIterator($arrayIterator, '/^test (\d+)/');
// Operation mode: Replace actual value with the matches
$regexIterator->setMode(RegexIterator::GET_MATCH);
foreach ($regexIterator as $key => $value) {
// print out the matched number(s)
echo $key . ' => ' . $value[1] . PHP_EOL;
}
?>
以上例程的输出类似于:
str1 => 1
str3 => 123
参见
- RegexIterator::getMode
RegexIterator::setPregFlags
Sets the regular expression flags
说明
public void
RegexIterator::setPregFlags ( <span
class="methodparam">int $preg_flags )
Sets the regular expression flags.
参数
preg_flags
The regular expression flags. See <span
class="methodname">RegexIterator::__construct for an overview
of available flags.
返回值
没有返回值。
范例
示例 #1 RegexIterator::setPregFlags example
Creates a new RegexIterator that filters all entries with where the array key starts with 'test'.
<?php
$test = array ('test 1', 'another test', 'test 123');
$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/^test/', RegexIterator::GET_MATCH);
$regexIterator->setPregFlags(PREG_OFFSET_CAPTURE);
foreach ($regexIterator as $key => $value) {
var_dump($value);
}
?>
以上例程的输出类似于:
array(1) {
[0]=>
array(2) {
[0]=>
string(4) "test"
[1]=>
int(0)
}
}
array(1) {
[0]=>
array(2) {
[0]=>
string(4) "test"
[1]=>
int(0)
}
}
参见
- RegexIterator::getPregFlags