I have many different strings, such as:
php
$names = [
"David England Mancester",
"David France Paris ",
"David Spain",
"Roger Spain",
"Trevor England",
"Trevor Russia Moscow",
"Lucy Russia",
"Richard J. Russia",
"Richard J. England Blyth",
"Richard M. England",
];
What I need is a way to return the matches, from the start of the string, that appear more than once.
php
$result = ["David", "Trever", "Richard J"]
I thought about splitting the first word from each string and returning any with a count of > 1
but my issue is it could be more than the first word.
This is a made-up sample, the real data will have around 400 strings, so it shouldn't be an issue if it's computationally time consuming, it will only happen once or twice in the apps life cycle.
Can anyone help at all with this?