Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are probably looking for something like this:</p> <pre><code>&lt;?php $items = array('admin/home', 'admin/home/page', 'admin/test', 'site', 'team/tree/template'); sort($items); $previous = array(); foreach ($items as $item) { $path = explode('/', $item); // $i is common nesting level of the previous item // e.g. 0 is nothing in common, 1 is one level in common, etc. for ($i = 0; $i &lt; min(count($path), count($previous)) &amp;&amp; ($path[$i] == $previous[$i]); $i++) { } // close &lt;ul&gt; from previous nesting levels: // that is, we close the amount of levels that the previous and this one have NOT in common for ($k = 0; $k &lt; count($previous)-$i-1; $k++) { echo "&lt;/ul&gt;"; } // $j is the current nesting level // we start at the common nesting level for ($j = $i; $j &lt; count($path); $j++) { // open &lt;ul&gt; for new nesting levels: // i.e., we open a level for every level deeper than the previous level if ($j &gt;= count($previous)) echo "&lt;ul&gt;"; echo "&lt;li&gt;"; // make the path bold if the end of the current path is reached if (count($path)-1 == $j) echo "&lt;b&gt;" . $path[$j] . "&lt;/b&gt;"; else echo $path[$j]; echo "&lt;/li&gt;"; } $previous = $path; } // close remaining &lt;ul&gt; for ($k = 0; $k &lt; count($previous); $k++) { echo "&lt;/ul&gt;"; } ?&gt; </code></pre> <p>Note that I order the array to make sure that all nested items come next to each other.</p> <p>It might have some bugs, but I guess you can work them out yourself. Note that I close the list items before opening a nested <code>&lt;ul&gt;</code>. This is not really how it should; I guess you actually should open the nested <code>&lt;ul&gt;</code> in the final <code>&lt;li&gt;</code> at that level, but you can figure that out yourself.</p> <p><strong>Update</strong> I updated the code to properly close the <code>&lt;ul&gt;</code>'s in some cases.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload