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. $aUsed = array();
  13. foreach ($aPathes as $sPath) {
  14. foreach ($aUsed as $iIndex => $sUsed) {
  15. if (substr($sUsed, 0, strlen($sPath)) == $sPath || substr($sPath, 0, strlen($sUsed)) == $sUsed) {
  16. if (strlen($sUsed) < strlen($sPath)) {
  17. array_splice($aUsed, $iIndex, 1);
  18. $aUsed[] = $sPath;
  19. }
  20. continue 2;
  21. }
  22. }
  23. $aUsed[] = $sPath;
  24. }
  25.  
  26. var_dump($aUsed);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(8) "/1/2/3/4"
  [1]=>
  string(8) "/1/2/3/5"
  [2]=>
  string(10) "/a/b/c/d/e"
}