I have an array like this:
$sports = array(
\'Softball - Counties\',
\'Softball - Eastern\',
\'Softball - North Harbour\',
\'Softball - South\',
\'Softball -
I would use a recursive algorithm like this:
1 - get the first string in the array 2 - call the recursive prefix method with the first string as a param 3 - if prefix is empty return no prefix 4 - loop through all the strings in the array 4.1 - if any of the strings does not start with the prefix 4.1.1 - call recursive prefix method with prefix - 1 as a param 4.2 return prefix