Since you found out that your data was obtained from some log file (i.e. not from FS directly, so it may not even be a real directory), you can use this simple method to get your array:
$data = 'abc\xyz
abc\def\ghi
abc\xyz\pqr';
$data = preg_split('/[\r\n]+/', $data);
$result = [];
$pointer = &$result;
foreach($data as $path)
{
$path = explode('\\', $path);
foreach($path as $key)
{
if(!isset($pointer[$key]))
{
$pointer[$key] = null;
$pointer = &$pointer[$key];
}
}
$pointer = &$result;
}
- this will lead to:
array (3) {
["abc"] =>
array (1) {
["xyz"] =>
Null
}
["def"] =>
array (1) {
["ghi"] =>
Null
}
["xyz"] =>
array (1) {
["pqr"] =>
Null
}
}