Home » PHP

PHP rewinddir() function with example

PHP rewinddir() function: Here, we are going to learn about the PHP rewinddir() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 13, 2019

PHP rewinddir() function

rewinddir() function is used to rewind/reset the directory handle which is created by the opendir() function.

Syntax:

    rewinddir(dir_handle);

Parameter(s):

  • dir_handle – it is an optional parameter which is used to specify the directory handle resource if we do not specify the directory handle resource – it assumes the last link opened with opendir() function.

Return value:

It returns nothing.

Example: PHP code to demonstrate example of rewinddir() function

<?php

$path = "/home";

//checking whether $path is a directory or not
//then, opening the directory and reading its files
if (is_dir($path)) {
    if ($dh = opendir($path)) {
        while (($file = readdir($dh)) !== false) {
            echo "File:" . $file . "<br/>";
        }
		
        //rewinding/reset the directory handle
        rewinddir();
		
		//reading the files again
        while (($file = readdir($dh)) !== false) {
            echo "File:" . $file . "<br/>";
        }
        
		//closing the directory
        closedir($dh);
    }
}
?>

Output

File:.
File:..
File:main.php
File:.
File:..
File:main.php

Reference: PHP rewinddir() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.