note 78977 modified in function.scandir by danbrown

From: Date: Thu, 28 Jan 2010 14:13:44 +0000
Subject: note 78977 modified in function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165441@lists.php.net to get a copy of this message
Since scandir() returns and array, here is a more concise method of dealing with the '.' and '..' problem when listing directories: <?php $target = '/'; $weeds = array('.', '..'); $directories = array_diff(scandir($target), $weeds); foreach($directories as $value) { if(is_dir($target.$value)) { echo $value.'<br />'; } } ?> --was-- Since scandir() returns and array, here is a more concise method of dealing with the '.' and '..' problem when listing directories: $target = '/'; $weeds = array('.', '..'); $directories = array_diff(scandir($target), $weeds); foreach($directories as $value) { if(is_dir($target.$value)) { echo $value.'<br />'; } } http://php.net/manual/en/function.scandir.php

« previous php.notes (#165441) next »