<?php
$arr = array (
0 => 'FOLDER./Images.Vacation.2018',
1 => './Images.Vacation.2018/Racoon001.jpg',
2 => './Images.Vacation.2018/Racoon002.txt',
3 => './Images.Vacation.2018/the.racoon.swimming.mp4',
4 => './Images.Vacation.2018/the.racoon.swimming.slv',
5 => 'FOLDER./WestImages',
6 => './WestImages/Ramco.txt',
7 => './WestImages/Ramco.jpg',
8 => 'FOLDER./WestImages/Subimages',
9 => './WestImages/Subimages/Image001.jpg',
10 => './WestImages/Subimages/Image002.jpg',
11 => './WestImages/West.Ramco.Swimming.mp4',
);
$folders = preg_grep("/^FOLDER.*/", $arr);
foreach($folders as $folder){
$result[] = $folder;
$result = array_merge($result, preg_grep("/^\." . str_replace(["FOLDER.", "/"], ["","\/"], $folder) . "\/[A-Za-z0-9\.]+$/", $arr));
}
var_dump($result);
preferences:
42.37 ms | 407 KiB | 5 Q