this code works, but i'd like to understand it

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
1885
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Feb 21, 2018 8:34 pm

Wed Feb 21, 2018 8:47 pm

The following code works to display the contents in an open directory.
I would appreciate an explanation for the following please:

if ($handle = opendir('.'))

The above code is an if condition obviously. How does this work? $handle = opendir('.')

and

while (false !== ($file = readdir($handle)))
What does this do? $file = readdir($handle)

Thanks :)
Please throw me a bone.


<?php
error_reporting(0);
$theList = array("*");
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".."&& $file != "index.php")
{
$thelist .= '<li><a href="'.$file.'"class = "bttn bttn2" target = "_blank">'.$file.'</a></li>';
}
}
closedir($handle);
}
?>

chorn
php-forum Fan User
php-forum Fan User
Posts: 559
Joined: Fri Apr 01, 2016 2:18 am

Wed Feb 21, 2018 11:25 pm

have a look at the functions documentation in the manual

http://php.net/

1885
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Feb 21, 2018 8:34 pm

Thu Feb 22, 2018 4:38 am


Post Reply