Given an array with n values, for example:
$arr[] = 'ABCDEFABC';
$arr[] = 'ABCDEFDEF';
$arr[] = 'ABCDEFGHI';
$arr[] = 'ABCDEFJKL';
how can I find the initial segment that matches all (or most, in the example bellow) values, in this case ABCDEF?
EDIT 2: NOT SOLVED, SEE ANSWER.
Even worse, given the following array:
$arr[] = 'ABCDEFABC';
$arr[] = 'ABCDEFDEF';
$arr[] = 'ABCDEFGHI';
$arr[] = 'ABCDEFJKL';
$arr[] = 'DEFABCABC';
$arr[] = 'DEFABCDEF';
$arr[] = 'DEFABCGHI';
$arr[] = 'DEFABCJKL';
how can I get:
$result[] = 'ABCDEF';
$result[] = 'DEFABC';
This one is tricky... What I'm trying to accomplish is the behavior of strspn() (where the order of the "mask" does matter, thank you Zed) applied to arrays.
EDIT: To clarify things up a bit what I want is to find the all the common letters that exist in the same index in all the values of the array (not sure if this made it easier or not!). In this second problem, since all chars don't match the index in the other values I need to match the maximum number of identical initial segments (in this case 2: ABCDEF and DEFABC).