array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'filesystemiterator.setflags.php', 1 => 'FilesystemIterator::setFlags', ), 'up' => array ( 0 => 'class.filesystemiterator.php', 1 => 'FilesystemIterator', ), 'prev' => array ( 0 => 'filesystemiterator.rewind.php', 1 => 'FilesystemIterator::rewind', ), 'next' => array ( 0 => 'class.filteriterator.php', 1 => 'FilterIterator', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', 'path' => 'reference/spl/filesystemiterator/setflags.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
FilesystemIterator::setFlags — Define opções de manipulação
Nenhum valor é retornado.
Exemplo #1 Exemplo de FilesystemIterator::key()
Este exemplo demonstra a diferença entre as opções FilesystemIterator::KEY_AS_PATHNAME e FilesystemIterator::KEY_AS_FILENAME.
<?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";
}
?>
A saída do exemplo acima no PHP 8.2 é semelhante a:
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