Could you give us some example data so that we can get a better idea of what the code is supposed to do, and what the results are supposed to be (is it just a pass/fail, the value of $prefix, or what?) - and what these "8 bytes of zeros" are of which you speak? In short - an elegant solution to what?
However, straight off I can see that a simple break statement could simplify the loop a wee bit:
while (true) {
for ($i=0;$i<count($list);$i++) {
if ( substr($list[$i],0,$test_length) != $test_prefix)
break;
}
$prefix = $test_prefix;
$test_length++;
$test_prefix = substr($list[0],0,$test_length);
}
The [man]array_filter[/man] function (perhaps along with some of the other functions in the same section) may help.