note 129755 added to function.scandir

From: Date: Mon, 16 Sep 2024 20:50:21 +0000
Subject: note 129755 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-221539@lists.php.net to get a copy of this message
I have designed a simple function that will change the order of scandir() in such a way, that the directories will be first (in ascending order) and files last (in ascending order). It also removes . and .. form scandir(). <?php function scandir_dir_first($path) { $raw_contents = array_diff(scandir($path), array('..', '.')); $dir_part = array(); $file_part = array(); foreach($raw_contents as $element) { if (is_dir($path . DIRECTORY_SEPARATOR . $element)) $dir_part[] = $element; else $file_part[] = $element; } return array_merge($dir_part, $file_part); } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 83.22.162.25) ---- Manual Page -- https://php.net/manual/en/function.scandir.php Edit -- https://main.php.net/note/edit/129755 Del: integrated -- https://main.php.net/note/delete/129755/integrated Del: useless -- https://main.php.net/note/delete/129755/useless Del: bad code -- https://main.php.net/note/delete/129755/bad+code Del: spam -- https://main.php.net/note/delete/129755/spam Del: non-english -- https://main.php.net/note/delete/129755/non-english Del: in docs -- https://main.php.net/note/delete/129755/in+docs Del: other reasons-- https://main.php.net/note/delete/129755 Reject -- https://main.php.net/note/reject/129755 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221539) next »