Open In App

PHP | FilesystemIterator setFlags() Function

The FilesystemIterator::setFlags() function is an inbuilt function in PHP which is used to set the handling flags.

Syntax:



void FilesystemIterator::setFlags( int $flags )

Parameters: This function accepts single parameter $flags which holds the handling flags to set.

Return Value: This function does not return any value.



Below programs illustrate the FilesystemIterator::setFlags() function in PHP:

Program 1:




<?php
  
// Create new file system iterator
$fileItr = new FilesystemIterator(__DIR__, 
    FilesystemIterator::CURRENT_AS_PATHNAME);
  
// Set the flags
$fileItr->setFlags(FilesystemIterator::KEY_AS_FILENAME);
  
// Get the flag 
$flag = $fileItr->getFlags(); 
    
// Display the flag 
var_dump($flag); 
  
?>

Output:
int(256)

Program 2:




<?php
  
// Create new file system iterator
$fileItr = new FilesystemIterator(__DIR__, 
    FilesystemIterator::CURRENT_AS_PATHNAME);
  
// Set the flag
$fileItr->setFlags(FilesystemIterator::CURRENT_AS_SELF);
  
// Get the flag 
$flag = $fileItr->getFlags(); 
    
// Display the flag 
var_dump($flag); 
  
?>

Output:
int(16)

Reference: https://www.php.net/manual/en/filesystemiterator.setflags.php


Article Tags :