title: PHP, regex and multi-level dashes and grouping together according to string occurrence
body: <p>I have a string which looks like this:</p>
  
  <pre><code>15-02-01-0000 
  15-02-02-0000
  15-02-03-0000 
  15-02-04-0000 
  15-02-05-0000 
  15-02-10-0000 
  15-02-10-9100 
  15-02-10-9101 
  15-15-81-0000 
  15-15-81-0024
  </code></pre>
  
  <p>So the expected output would be:
  All account grouping separated by "-" dashes for example: <code>15-02-01-0000</code> there is 3 grouping </p>
  
  <ul>
  <li>start with 15  </li>
  <li>start with 15-02</li>
  <li>start with 15-02-01</li>
  </ul>
  
  <p>So the expected output would be:</p>
  
  <p>First it will show </p>
  
  <pre><code>15  --&gt; All account start with "15"
    15-02 --&gt; All account start with "15-02"
      15-02-01 -- All accounts start with "15-02-01"
        15-02-01-0000 
      15-02-02 -- All accounts start with 15-02-02
        15-02-02-0000
      15-02-03 -- onwards like above
        15-02-03-0000 
      15-02-04 
        15-02-04-0000 
      15-02-05 
        15-02-05-0000 
      15-02-10 
        15-02-10-0000 
        15-02-10-9100 
        15-02-10-9101 
    15-15 
      15-15-81 
        15-15-81-0000 
        15-15-81-0024
  </code></pre>
  
  <p>I tried to use <code>substr</code>: </p>
  
  <pre><code>$res = substr("15-15-81-0024",3,2);
  if ($res == "15") {
  
  } else if ($res &lt; 10 &amp;&amp; $res != 00) {
  
  } else {
  
  }
  </code></pre>
  
  <p>But not working to put grouping.
  Could you please suggest any good way?</p>