5

Table flat in the tree view

 2 years ago
source link: https://www.codesd.com/item/table-flat-in-the-tree-view.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Table flat in the tree view

advertisements

I am currently stuck on the modification of an array "flat" to a array structure of a tree.

I have an array to the type:

$folders = array(
    array('Name' => 'Archive', 'Value' => 'Archive', 'Attributes' => 32, 'Delimiters' => '/'),
    array('Name' => 'Folder1', 'Value' => 'Archive/Folder1', 'Attributes' => 32, 'Delimiters' => '/'),
    array('Name' => 'FolderA', 'Value' => 'Archive/Folder1/DossierA', 'Attributes' => 64, 'Delimiters' => '/'),
    array('Name' => 'Folder2', 'Value' => 'Archive/Folder2', 'Attributes' => 32, 'Delimiters' => '/'),
    array('Name' => 'FolderA', 'Value' => 'Archive/Folder2/FolderA', 'Attributes' => 32, 'Delimiters' => '/'),
    array('Name' => 'FolderB', 'Value' => 'Archive/Folder2/FolderA/FolderB', 'Attributes' => 64, 'Delimiters' => '/'),
);

and I would get an array to the type:

$treefolders = array(
    array('Name' => 'Archive', 'Value' => 'Archive', 'Attributes' => 32, 'Delimiters' => '/', 'subnode' =>
        array('Name' => 'Folder1', 'Value' => 'Archive/Folder1', 'Attributes' => 32, 'Delimiters' => '/', 'subnode' =>
            array('Name' => 'FolderA', 'Value' => 'Archive/Folder1/FolderA', 'Attributes' => 64, 'Delimiters' => '/')
        ),
        array('Name' => 'Folder2', 'Value' => 'Archive/Folder2', 'Attributes' => 32, 'Delimiters' => '/', 'subnode' =>
            array('Name' => 'FolderA', 'Value' => 'Archive/Folder2/FolderA', 'Attributes' => 32, 'Delimiters' => '/', 'subnode' =>
                array('Name' => 'FolderB', 'Value' => 'Archive/Folder2/FolderA/FolderB', 'Attributes' => 64, 'Delimiters' => '/')
            )
        )
    )
);

I do not know how to get to the last result.

Can you help me?


This is not possible, in PHP arrays cannot be used as array keys. You are able to use just the directory name as a key.

The best solution is to change the way you create your array or rethink your code and/or data structure. There is probably a much easier solution to your problem, maybe re-ask your question. See the XY problem.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK