略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: FilesystemIterator::setFlags

2024-11-15

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

以上例程的输出类似于:

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

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

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/filesystemiterator.setflags.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3