Tetris-ing an array

后端 未结 16 1395
时光取名叫无心
时光取名叫无心 2021-01-30 15:38

Consider the following array:

/www/htdocs/1/sites/lib/abcdedd
/www/htdocs/1/sites/conf/xyz
/www/htdocs/1/sites/conf/abc/         


        
16条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 16:20

    The problem can be simplified if just viewed from the string comparison angle. This is probably faster than array-splitting:

    $longest = $tetris[0];  # or array_pop()
    foreach ($tetris as $cmp) {
            while (strncmp($longest+"/", $cmp, strlen($longest)+1) !== 0) {
                    $longest = substr($longest, 0, strrpos($longest, "/"));
            }
    }
    

提交回复
热议问题