fork download
  1. <?php
  2.  
  3. $aPathes = array(
  4. '/a/b',
  5. '/a',
  6. '/1/2/3/4',
  7. '/1/2',
  8. '/1/2/3/5',
  9. '/a/b/c/d/e'
  10. );
  11.  
  12. function getDepth($sPath) {
  13. return substr_count($sPath, '/');
  14. }
  15. $aPathDepths = array_map('getDepth', $aPathes);
  16.  
  17. arsort($aPathDepths);
  18. foreach ($aPathDepths as $iKey => $iDepth) {
  19. echo $aPathes[$iKey] . "\n";
  20. }
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
/a/b/c/d/e
/1/2/3/5
/1/2/3/4
/1/2
/a/b
/a