 <p>Well, there are already some solutions here but, just because it was fun:</p> <pre><code>$values = array( '/www/htdocs/1/sites/lib/abcdedd', '/www/htdocs/1/sites/conf/xyz', '/www/htdocs/1/sites/conf/abc/def', '/www/htdocs/1/sites/htdocs/xyz', '/www/htdocs/1/sites/lib2/abcdedd' ); function findCommon($values){ $common = false; foreach($values as &amp;$p){ $p = explode('/', $p); if(!$common){ $common = $p; } else { $common = array_intersect_assoc($common, $p); } } return $common; } function removeCommon($values, $common){ foreach($values as &amp;$p){ $p = explode('/', $p); $p = array_diff_assoc($p, $common); $p = implode('/', $p); } return $values; } echo '&lt;pre&gt;'; print_r(removeCommon($values, findCommon($values))); echo '&lt;/pre&gt;'; </code></pre> <p>Output:</p> <pre><code>Array ( [0] =&gt; lib/abcdedd [1] =&gt; conf/xyz [2] =&gt; conf/abc/def [3] =&gt; htdocs/xyz [4] =&gt; lib2/abcdedd ) </code></pre>