DirectoryIterator
PHP Manual

DirectoryIterator::key

(PHP 5)

DirectoryIterator::keyReturn the key for the current DirectoryIterator item

Описание

public string DirectoryIterator::key ( void )

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

Вж. също


DirectoryIterator
PHP Manual