PHP 8.4.2 Released!

FilesystemIterator::setFlags

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

FilesystemIterator::setFlagsSets handling flags

Опис

public FilesystemIterator::setFlags(int $flags): void

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";
}
?>

В PHP 8.2 поданий вище приклад виведе щось схоже на:

Key as Pathname:
/www/examples/.
/www/examples/..
/www/examples/apple.jpg
/www/examples/banana.jpg
/www/examples/example.php

Key as Filename:
.
..
apple.jpg
banana.jpg
example.php

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top