DirectoryIterator::key

(PHP 5, PHP 7)

DirectoryIterator::keyReturn the key for the current DirectoryIterator item

说锟斤拷

public DirectoryIterator::key ( void ) : string

Get the key for the current DirectoryIterator item.

锟斤拷锟斤拷

锟剿猴拷锟斤拷没锟叫诧拷锟斤拷锟斤拷

锟斤拷锟斤拷值

The key for the current DirectoryIterator item.

锟斤拷锟斤拷

Example #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

锟轿硷拷